Kaynağa Gözat

Split up cases for producing and consuming UDP socket creation

Signed-off-by: Martin Melik-Merkumians <melik-merkumians@acin.tuwien.ac.at>
Martin Melik-Merkumians 7 yıl önce
ebeveyn
işleme
13478a7454

+ 2 - 1
source/src/cip/cipioconnection.c

@@ -776,7 +776,8 @@ EipStatus SendConnectedData(CipConnectionObject *connection_object) {
   /* TODO think of adding an own send buffer to each connection object in order to preset up the whole message on connection opening and just change the variable data items e.g., sequence number */
 
   CipCommonPacketFormatData *common_packet_format_data =
-    &g_common_packet_format_data_item;                                                      /* TODO think on adding a CPF data item to the S_CIP_ConnectionObject in order to remove the code here or even better allocate memory in the connection object for storing the message to send and just change the application data*/
+    &g_common_packet_format_data_item;
+  /* TODO think on adding a CPF data item to the S_CIP_ConnectionObject in order to remove the code here or even better allocate memory in the connection object for storing the message to send and just change the application data*/
 
   connection_object->eip_level_sequence_count_producing++;
 

+ 10 - 3
source/src/ports/generic_networkhandler.c

@@ -777,7 +777,7 @@ EipStatus HandleDataOnTcpSocket(int socket) {
  * @param communciation_direction Consuming or producing port
  * @param socket_data Data for socket creation
  *
- * @return the socket handle if successful, else -1 */
+ * @return the socket handle if successful, else kEipInvalidSocket */
 int CreateUdpSocket(UdpCommuncationDirection communication_direction,
                     struct sockaddr_in *socket_data,
                     CipUsint qos_for_socket) {
@@ -786,8 +786,15 @@ int CreateUdpSocket(UdpCommuncationDirection communication_direction,
 
   socklen_t peer_address_length = sizeof(struct sockaddr_in);
   /* create a new UDP socket */
-  if ( ( new_socket =
-           socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) ) == kEipInvalidSocket ) {
+  if(kUdpCommuncationDirectionConsuming == communication_direction) {
+    new_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+  }
+
+  if(kUdpCommuncationDirectionProducing == communication_direction) {
+    new_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+  }
+
+  if (new_socket == kEipInvalidSocket) {
     int error_code = GetSocketErrorNumber();
     char *error_message = GetErrorMessage(error_code);
     OPENER_TRACE_ERR("networkhandler: cannot create UDP socket: %d- %s\n",