Changeset 24de663 in network-demos
- Timestamp:
- 06/11/99 14:10:59 (24 years ago)
- Branches:
- 4.11, 57a009d5b89e72f488ab655184e6a33bb0fe6b7f, netdemos-4-5-branch, network-demos-4-10-branch, network-demos-4-6-branch, network-demos-4-7-branch, network-demos-4-8-branch, network-demos-4-9-branch, rtems-4-5-branch
- Children:
- 45c129b
- Parents:
- 2cf4ec4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
select/test.c
r2cf4ec4 r24de663 30 30 #define CLIENT_COUNT 2 31 31 32 static void 33 echoServer (unsigned short port) 32 static int clientfd[CLIENT_COUNT]; 33 34 static void 35 getClients (unsigned short port) 34 36 { 35 37 int s, s1; 36 38 struct sockaddr_in myAddr, farAddr; 37 39 int addrlen; 38 rtems_id tid; 39 rtems_task_priority my_priority; 40 rtems_status_code sc; 41 char c = 'a'; 42 fd_set clientfdset; 43 int clientCount, clientfd[CLIENT_COUNT]; 44 int topfd = 0; 45 46 FD_ZERO (&clientfdset); 40 int clientCount; 41 47 42 printf ("Create socket.\n"); 48 43 s = socket (AF_INET, SOCK_STREAM, 0); … … 71 66 else 72 67 printf ("ACCEPTED:%lX\n", ntohl (farAddr.sin_addr.s_addr)); 68 clientfd[clientCount] = s1; 69 } 70 71 close (s); 72 } 73 74 static void 75 echoServer (unsigned short port) 76 { 77 fd_set clientfdset; 78 int clientCount; 79 int topfd = 0; 80 81 getClients (port); 82 83 FD_ZERO (&clientfdset); 84 85 for (clientCount = 0 ; clientCount < CLIENT_COUNT ; clientCount++) { 86 int s1; 87 88 s1 = clientfd[clientCount]; 73 89 FD_SET (s1, &clientfdset); 74 90 if (s1 > topfd) 75 91 topfd = s1; 76 clientfd[clientCount] = s1;77 92 } 78 93 … … 116 131 printf ("EOF\n"); 117 132 FD_CLR (fd, &clientfdset); 133 close (fd); 118 134 if (--clientCount == 0) 119 135 return; … … 125 141 } 126 142 143 static rtems_id tid; 144 145 static void 146 wakeup (struct socket *so, caddr_t arg) 147 { 148 rtems_event_send (tid, RTEMS_EVENT_0 + (int) arg); 149 } 150 151 static void 152 echoServer2 (port) 153 { 154 struct sockwakeup sw, sw2; 155 int swlen; 156 int clientCount; 157 rtems_event_set clientEvents; 158 159 getClients (port); 160 161 sw.sw_pfn = &wakeup; 162 clientEvents = 0; 163 for (clientCount = 0 ; clientCount < CLIENT_COUNT ; clientCount++) { 164 sw.sw_arg = (caddr_t) clientCount; 165 if (setsockopt (clientfd[clientCount], SOL_SOCKET, 166 SO_RCVWAKEUP, &sw, sizeof sw) < 0) 167 rtems_panic ("setsockopt failed: %s", 168 strerror (errno)); 169 swlen = sizeof sw2; 170 if (getsockopt (clientfd[clientCount], SOL_SOCKET, 171 SO_RCVWAKEUP, &sw2, &swlen) < 0) 172 rtems_panic ("getsockopt failed: %s", 173 strerror (errno)); 174 if (swlen != sizeof sw2 175 || sw2.sw_pfn != &wakeup 176 || (int) sw2.sw_arg != clientCount) 177 rtems_panic ("getsockopt mismatch"); 178 179 clientEvents |= RTEMS_EVENT_0 + clientCount; 180 } 181 182 if (rtems_task_ident (RTEMS_SELF, RTEMS_SEARCH_LOCAL_NODE, &tid) 183 != RTEMS_SUCCESSFUL) 184 rtems_panic ("rtems_task_ident failed"); 185 186 for (;;) { 187 rtems_event_set events; 188 rtems_status_code status; 189 int i; 190 191 status = rtems_event_receive (clientEvents, 192 RTEMS_WAIT | RTEMS_EVENT_ANY, 193 RTEMS_MILLISECONDS_TO_TICKS (5000), 194 &events); 195 196 if (status == RTEMS_TIMEOUT) { 197 printf ("Timeout\n"); 198 continue; 199 } 200 201 for (i = 0; i < CLIENT_COUNT; ++i) { 202 if (events == 0) 203 break; 204 if (events & (i + RTEMS_EVENT_0)) { 205 int fd; 206 char buf[200]; 207 int nread; 208 209 fd = clientfd[i]; 210 printf ("Activity on file descriptor %d.\n", fd); 211 events &= ~ (i + RTEMS_EVENT_0); 212 nread = read (fd, buf, sizeof buf); 213 if (nread < 0) { 214 printf ("Read error %s.\n", strerror (errno)); 215 return; 216 } 217 if (nread == 0) { 218 printf ("EOF\n"); 219 clientEvents &= ~ (i + RTEMS_EVENT_0); 220 close (fd); 221 if (--clientCount == 0) 222 return; 223 } 224 printf ("Read %d.\n", nread); 225 } 226 } 227 } 228 } 229 127 230 void 128 231 doSocket (void)
Note: See TracChangeset
for help on using the changeset viewer.