]> git.proxmox.com Git - mirror_edk2.git/blobdiff - AppPkg/Applications/Sockets/DataSink/DataSink.c
Update the sockets applications
[mirror_edk2.git] / AppPkg / Applications / Sockets / DataSink / DataSink.c
index 911cf369400e09aa15a35ac4d5d2d521c863953e..8223ead118079e3b652eb7d7f32c7d4ea122a4c2 100644 (file)
@@ -51,9 +51,9 @@ BOOLEAN bTimerRunning;
 struct sockaddr_in LocalAddress;\r
 EFI_EVENT pTimer;\r
 int ListenSocket;\r
-UINT8 Buffer [ DATA_BUFFER_SIZE ];\r
-struct pollfd PollFd [ MAX_CONNECTIONS ];\r
-DT_PORT Port [ MAX_CONNECTIONS ];\r
+UINT8 Buffer[ DATA_BUFFER_SIZE ];\r
+struct pollfd PollFd[ MAX_CONNECTIONS ];\r
+DT_PORT Port[ MAX_CONNECTIONS ];\r
 nfds_t MaxPort;\r
 \r
 \r
@@ -136,17 +136,17 @@ SocketAccept (
       //  Allocate a port\r
       //\r
       Index = MaxPort++;\r
-      PollFd [ Index ].fd = ListenSocket;\r
-      PollFd [ Index ].events = POLLRDNORM | POLLHUP;\r
-      PollFd [ Index ].revents = 0;\r
-      Port [ Index ].BytesAverage = 0;\r
-      Port [ Index ].BytesPrevious = 0;\r
-      Port [ Index ].BytesTotal = 0;\r
-      Port [ Index ].Samples = 0;\r
-      Port [ Index ].RemoteAddress.sin_len = 0;\r
-      Port [ Index ].RemoteAddress.sin_family = 0;\r
-      Port [ Index ].RemoteAddress.sin_port = 0;\r
-      Port [ Index ].RemoteAddress.sin_addr.s_addr= 0;\r
+      PollFd[ Index ].fd = ListenSocket;\r
+      PollFd[ Index ].events = POLLRDNORM | POLLHUP;\r
+      PollFd[ Index ].revents = 0;\r
+      Port[ Index ].BytesAverage = 0;\r
+      Port[ Index ].BytesPrevious = 0;\r
+      Port[ Index ].BytesTotal = 0;\r
+      Port[ Index ].Samples = 0;\r
+      Port[ Index ].RemoteAddress.sin_len = 0;\r
+      Port[ Index ].RemoteAddress.sin_family = 0;\r
+      Port[ Index ].RemoteAddress.sin_port = 0;\r
+      Port[ Index ].RemoteAddress.sin_addr.s_addr= 0;\r
     }\r
   }\r
 \r
@@ -242,8 +242,7 @@ SocketNew (
                 "0x%08x: Socket created\r\n",\r
                 ListenSocket ));\r
     }\r
-    else\r
-    {\r
+    else {\r
       Status = EFI_NOT_STARTED;\r
     }\r
   }\r
@@ -312,16 +311,16 @@ SocketPoll (
         //\r
         //  Account for this descriptor\r
         //\r
-        if ( 0 != PollFd [ Index ].revents ) {\r
+        if ( 0 != PollFd[ Index ].revents ) {\r
           FdCount -= 1;\r
         }\r
 \r
         //\r
         //  Check for a broken connection\r
         //\r
-        if ( 0 != ( PollFd [ Index ].revents & POLLHUP )) {\r
+        if ( 0 != ( PollFd[ Index ].revents & POLLHUP )) {\r
           bRemoveSocket = TRUE;\r
-          if ( ListenSocket == PollFd [ Index ].fd ) {\r
+          if ( ListenSocket == PollFd[ Index ].fd ) {\r
             bListenError = TRUE;\r
             DEBUG (( DEBUG_ERROR,\r
                       "ERROR - Network closed on listen socket, errno: %d\r\n",\r
@@ -330,37 +329,37 @@ SocketPoll (
           else {\r
             DEBUG (( DEBUG_ERROR,\r
                       "ERROR - Network closed on socket %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                      Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                      ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                      ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                      ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                      htons ( Port [ Index ].RemoteAddress.sin_port ),\r
+                      Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                      ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                      ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                      ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                      htons ( Port[ Index ].RemoteAddress.sin_port ),\r
                       errno ));\r
 \r
             //\r
             //  Close the socket\r
             //\r
-            CloseStatus = close ( PollFd [ Index ].fd );\r
+            CloseStatus = close ( PollFd[ Index ].fd );\r
             if ( 0 == CloseStatus ) {\r
               bRemoveSocket = TRUE;\r
               DEBUG (( DEBUG_INFO,\r
                         "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
-                        PollFd [ Index ].fd,\r
-                        Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port [ Index ].RemoteAddress.sin_port )));\r
+                        PollFd[ Index ].fd,\r
+                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                        htons ( Port[ Index ].RemoteAddress.sin_port )));\r
             }\r
             else {\r
               DEBUG (( DEBUG_ERROR,\r
                         "ERROR - Failed to close socket 0x%08x for %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                        PollFd [ Index ].fd,\r
-                        Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port [ Index ].RemoteAddress.sin_port ),\r
+                        PollFd[ Index ].fd,\r
+                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                        htons ( Port[ Index ].RemoteAddress.sin_port ),\r
                         errno ));\r
             }\r
           }\r
@@ -369,11 +368,11 @@ SocketPoll (
         //\r
         //  Check for a connection or read data\r
         //\r
-        if ( 0 != ( PollFd [ Index ].revents & POLLRDNORM )) {\r
+        if ( 0 != ( PollFd[ Index ].revents & POLLRDNORM )) {\r
           //\r
           //  Check for a connection\r
           //\r
-          if ( ListenSocket == PollFd [ Index ].fd ) {\r
+          if ( ListenSocket == PollFd[ Index ].fd ) {\r
             //\r
             //  Another client connection was received\r
             //\r
@@ -416,7 +415,7 @@ SocketPoll (
                   bRemoveSocket = TRUE;\r
                   DEBUG (( DEBUG_INFO,\r
                             "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
-                            PollFd [ Index ].fd,\r
+                            PollFd[ Index ].fd,\r
                             RemoteAddress.sin_addr.s_addr & 0xff,\r
                             ( RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
                             ( RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
@@ -426,7 +425,7 @@ SocketPoll (
                 else {\r
                   DEBUG (( DEBUG_ERROR,\r
                             "ERROR - Failed to close socket 0x%08x, errno: %d\r\n",\r
-                            PollFd [ Index ].fd,\r
+                            PollFd[ Index ].fd,\r
                             errno ));\r
                 }\r
 \r
@@ -436,8 +435,7 @@ SocketPoll (
                 //\r
                 Status = EFI_SUCCESS;\r
               }\r
-              else\r
-              {\r
+              else {\r
                 //\r
                 //  Display the connection\r
                 //\r
@@ -452,17 +450,17 @@ SocketPoll (
                 //  Allocate the client connection\r
                 //\r
                 Index = MaxPort++;\r
-                Port [ Index ].BytesAverage = 0;\r
-                Port [ Index ].BytesPrevious = 0;\r
-                Port [ Index ].BytesTotal = 0;\r
-                Port [ Index ].Samples = 0;\r
-                Port [ Index ].RemoteAddress.sin_len = RemoteAddress.sin_len;\r
-                Port [ Index ].RemoteAddress.sin_family = RemoteAddress.sin_family;\r
-                Port [ Index ].RemoteAddress.sin_port = RemoteAddress.sin_port;\r
-                Port [ Index ].RemoteAddress.sin_addr = RemoteAddress.sin_addr;\r
-                PollFd [ Index ].fd = Socket;\r
-                PollFd [ Index ].events = POLLRDNORM | POLLHUP;\r
-                PollFd [ Index ].revents = 0;\r
+                Port[ Index ].BytesAverage = 0;\r
+                Port[ Index ].BytesPrevious = 0;\r
+                Port[ Index ].BytesTotal = 0;\r
+                Port[ Index ].Samples = 0;\r
+                Port[ Index ].RemoteAddress.sin_len = RemoteAddress.sin_len;\r
+                Port[ Index ].RemoteAddress.sin_family = RemoteAddress.sin_family;\r
+                Port[ Index ].RemoteAddress.sin_port = RemoteAddress.sin_port;\r
+                Port[ Index ].RemoteAddress.sin_addr = RemoteAddress.sin_addr;\r
+                PollFd[ Index ].fd = Socket;\r
+                PollFd[ Index ].events = POLLRDNORM | POLLHUP;\r
+                PollFd[ Index ].revents = 0;\r
               }\r
             }\r
           }\r
@@ -470,7 +468,7 @@ SocketPoll (
             //\r
             //  Data received\r
             //\r
-            BytesReceived = read ( PollFd [ Index ].fd,\r
+            BytesReceived = read ( PollFd[ Index ].fd,\r
                                    &Buffer,\r
                                    sizeof ( Buffer ));\r
             if ( 0 < BytesReceived ) {\r
@@ -479,13 +477,13 @@ SocketPoll (
               //\r
               DEBUG (( DEBUG_INFO,\r
                         "0x%08x: Socket received 0x%08x bytes from %d.%d.%d.%d:%d\r\n",\r
-                        PollFd [ Index ].fd,\r
+                        PollFd[ Index ].fd,\r
                         BytesReceived,\r
-                        Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port [ Index ].RemoteAddress.sin_port )));\r
+                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                        htons ( Port[ Index ].RemoteAddress.sin_port )));\r
 \r
               //\r
               //  Synchronize with the TimerCallback routine\r
@@ -495,7 +493,7 @@ SocketPoll (
               //\r
               //  Account for the data received\r
               //\r
-              Port [ Index ].BytesTotal += BytesReceived;\r
+              Port[ Index ].BytesTotal += BytesReceived;\r
 \r
               //\r
               //  Release the synchronization with the TimerCallback routine\r
@@ -508,33 +506,33 @@ SocketPoll (
               //\r
               DEBUG (( DEBUG_INFO,\r
                         "ERROR - Receive failure for %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                        Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                        ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( Port [ Index ].RemoteAddress.sin_port ),\r
+                        Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                        ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                        htons ( Port[ Index ].RemoteAddress.sin_port ),\r
                         errno ));\r
-              CloseStatus = close ( PollFd [ Index ].fd );\r
+              CloseStatus = close ( PollFd[ Index ].fd );\r
               if ( 0 == CloseStatus ) {\r
                 bRemoveSocket = TRUE;\r
                 DEBUG (( DEBUG_INFO,\r
                           "0x%08x: Socket closed for %d.%d.%d.%d:%d\r\n",\r
-                          PollFd [ Index ].fd,\r
-                          Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                          ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                          ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                          ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( Port [ Index ].RemoteAddress.sin_port )));\r
+                          PollFd[ Index ].fd,\r
+                          Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( Port[ Index ].RemoteAddress.sin_port )));\r
               }\r
               else {\r
                 DEBUG (( DEBUG_ERROR,\r
                           "ERROR - Failed to close socket 0x%08x for %d.%d.%d.%d:%d, errno: %d\r\n",\r
-                          PollFd [ Index ].fd,\r
-                          Port [ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
-                          ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
-                          ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
-                          ( Port [ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( Port [ Index ].RemoteAddress.sin_port ),\r
+                          PollFd[ Index ].fd,\r
+                          Port[ Index ].RemoteAddress.sin_addr.s_addr & 0xff,\r
+                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 8 ) & 0xff,\r
+                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 16 ) & 0xff,\r
+                          ( Port[ Index ].RemoteAddress.sin_addr.s_addr >> 24 ) & 0xff,\r
+                          htons ( Port[ Index ].RemoteAddress.sin_port ),\r
                           errno ));\r
               }\r
             }\r
@@ -553,23 +551,23 @@ SocketPoll (
         if ( bRemoveSocket ) {\r
           DEBUG (( DEBUG_INFO,\r
                     "0x%08x: Socket removed from polling\r\n",\r
-                    PollFd [ Index ].fd ));\r
+                    PollFd[ Index ].fd ));\r
           MaxPort -= 1;\r
           for ( Entry = Index + 1; MaxPort >= Entry; Entry++ ) {\r
             EntryPrevious = Entry;\r
-            Port [ EntryPrevious ].BytesAverage = Port [ Entry ].BytesAverage;\r
-            Port [ EntryPrevious ].BytesPrevious = Port [ Entry ].BytesPrevious;\r
-            Port [ EntryPrevious ].BytesTotal = Port [ Entry ].BytesTotal;\r
-            Port [ EntryPrevious ].RemoteAddress.sin_len = Port [ Entry ].RemoteAddress.sin_len;\r
-            Port [ EntryPrevious ].RemoteAddress.sin_family = Port [ Entry ].RemoteAddress.sin_family;\r
-            Port [ EntryPrevious ].RemoteAddress.sin_port = Port [ Entry ].RemoteAddress.sin_port;\r
-            Port [ EntryPrevious ].RemoteAddress.sin_addr.s_addr = Port [ Entry ].RemoteAddress.sin_addr.s_addr;\r
-            Port [ EntryPrevious ].Samples = Port [ Entry ].Samples;\r
-            PollFd [ EntryPrevious ].events = PollFd [ Entry ].events;\r
-            PollFd [ EntryPrevious ].fd = PollFd [ Entry ].fd;\r
-            PollFd [ EntryPrevious ].revents = PollFd [ Entry ].revents;\r
+            Port[ EntryPrevious ].BytesAverage = Port[ Entry ].BytesAverage;\r
+            Port[ EntryPrevious ].BytesPrevious = Port[ Entry ].BytesPrevious;\r
+            Port[ EntryPrevious ].BytesTotal = Port[ Entry ].BytesTotal;\r
+            Port[ EntryPrevious ].RemoteAddress.sin_len = Port[ Entry ].RemoteAddress.sin_len;\r
+            Port[ EntryPrevious ].RemoteAddress.sin_family = Port[ Entry ].RemoteAddress.sin_family;\r
+            Port[ EntryPrevious ].RemoteAddress.sin_port = Port[ Entry ].RemoteAddress.sin_port;\r
+            Port[ EntryPrevious ].RemoteAddress.sin_addr.s_addr = Port[ Entry ].RemoteAddress.sin_addr.s_addr;\r
+            Port[ EntryPrevious ].Samples = Port[ Entry ].Samples;\r
+            PollFd[ EntryPrevious ].events = PollFd[ Entry ].events;\r
+            PollFd[ EntryPrevious ].fd = PollFd[ Entry ].fd;\r
+            PollFd[ EntryPrevious ].revents = PollFd[ Entry ].revents;\r
           }\r
-          PollFd [ MaxPort ].fd = -1;\r
+          PollFd[ MaxPort ].fd = -1;\r
           Index -= 1;\r
         }\r
 \r
@@ -625,31 +623,31 @@ TimerCallback (
     //\r
     //  Determine if any data was received\r
     //\r
-    BytesReceived = Port [ Index ].BytesTotal;\r
-    if (( ListenSocket != PollFd [ Index ].fd )\r
+    BytesReceived = Port[ Index ].BytesTotal;\r
+    if (( ListenSocket != PollFd[ Index ].fd )\r
       && ( 0 != BytesReceived )) {\r
       //\r
       //  Update the average bytes per second\r
       //\r
-      DeltaBytes = Port [ Index ].BytesAverage >> AVERAGE_SHIFT_COUNT;\r
-      Port [ Index ].BytesAverage -= DeltaBytes;\r
-      DeltaBytes = BytesReceived - Port [ Index ].BytesPrevious;\r
-      Port [ Index ].BytesPrevious = BytesReceived;\r
-      Port [ Index ].BytesAverage += DeltaBytes;\r
+      DeltaBytes = Port[ Index ].BytesAverage >> AVERAGE_SHIFT_COUNT;\r
+      Port[ Index ].BytesAverage -= DeltaBytes;\r
+      DeltaBytes = BytesReceived - Port[ Index ].BytesPrevious;\r
+      Port[ Index ].BytesPrevious = BytesReceived;\r
+      Port[ Index ].BytesAverage += DeltaBytes;\r
 \r
       //\r
       //  Separate the samples\r
       //\r
-      if (( 2 << AVERAGE_SHIFT_COUNT ) == Port [ Index ].Samples ) {\r
+      if (( 2 << AVERAGE_SHIFT_COUNT ) == Port[ Index ].Samples ) {\r
         Print ( L"---------- Stable average ----------\r\n" );\r
       }\r
-      Port [ Index ].Samples += 1;\r
+      Port[ Index ].Samples += 1;\r
 \r
       //\r
       //  Display the data rate\r
       //\r
       Delta = (UINT32)( DeltaBytes >> DATA_RATE_UPDATE_SHIFT );\r
-      Average = Port [ Index ].BytesAverage >> ( AVERAGE_SHIFT_COUNT + DATA_RATE_UPDATE_SHIFT );\r
+      Average = Port[ Index ].BytesAverage >> ( AVERAGE_SHIFT_COUNT + DATA_RATE_UPDATE_SHIFT );\r
       if ( Average < RANGE_SWITCH ) {\r
         Print ( L"%d Bytes/sec, Ave: %d Bytes/Sec\r\n",\r
                 Delta,\r
@@ -919,8 +917,7 @@ main (
   //\r
   //  Use for/break instead of goto\r
   //\r
-  for ( ; ; )\r
-  {\r
+  for ( ; ; ) {\r
     //\r
     //  Create the timer\r
     //\r