Changeset 9 in Main for trunk/Server
- Timestamp:
- Sep 13, 2024, 8:28:43 PM (2 months ago)
- Location:
- trunk/Server
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/main.c
r8 r9 50 50 } 51 51 cm_log("Daemon", "Ready"); 52 tw_server_loop(); 52 53 } -
trunk/Server/server.c
r8 r9 25 25 fd_set fdset; 26 26 int sockcount = 0; 27 int sockets[MAX_PORTS];28 27 29 28 #ifdef NO_IPV6 30 struct sockaddr_in addresses[MAX_PORTS]; 29 #define SOCKADDR struct sockaddr_in 31 30 #else 32 struct sockaddr_in6 addresses[MAX_PORTS]; 31 #define SOCKADDR struct sockaddr_in6 33 32 #endif 33 SOCKADDR addresses[MAX_PORTS]; 34 int sockets[MAX_PORTS]; 34 35 35 36 void close_socket(int sock) { … … 105 106 return 1; 106 107 } 108 FD_SET(sock, &fdset); 107 109 sockets[i] = sock; 108 110 } 109 111 return 0; 110 112 } 113 114 void tw_server_loop(void){ 115 struct timeval tv; 116 while(1){ 117 tv.tv_sec = 1; 118 tv.tv_usec = 0; 119 int ret = select(sockcount, &fdset, NULL, NULL, &tv); 120 if(ret == -1){ 121 break; 122 }else if(ret > 0){ 123 /* connection */ 124 printf("!\n"); 125 int i; 126 for(i = 0; i < sockcount; i++){ 127 if(FD_ISSET(sockets[i], &fdset)){ 128 SOCKADDR claddr; 129 int clen = sizeof(claddr); 130 int sock = accept(sockets[i], (struct sockaddr*)&claddr, &clen); 131 close_socket(sock); 132 } 133 } 134 } 135 } 136 } -
trunk/Server/tw_server.h
r8 r9 5 5 6 6 int tw_server_init(void); 7 void tw_server_loop(void); 7 8 8 9 #endif
Note:
See TracChangeset
for help on using the changeset viewer.