Rev 4737 | Rev 4743 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4737 | Rev 4741 | ||
---|---|---|---|
Line 83... | Line 83... | ||
83 | void print_help( void ){ |
83 | void print_help( void ){ |
84 | printf( |
84 | printf( |
85 | "Network Echo aplication\n" \ |
85 | "Network Echo aplication\n" \ |
86 | "Usage: echo [options]\n" \ |
86 | "Usage: echo [options]\n" \ |
87 | "Where options are:\n" \ |
87 | "Where options are:\n" \ |
- | 88 | "-b backlog | --backlog=size\n" \ |
|
- | 89 | "\tThe size of the accepted sockets queue. Only for SOCK_STREAM. The default is 3.\n" \ |
|
- | 90 | "\n" \ |
|
88 | "-c count | --count=count\n" \ |
91 | "-c count | --count=count\n" \ |
89 | "\tThe number of received messages to handle. A negative number means infinity. The default is infinity.\n" \ |
92 | "\tThe number of received messages to handle. A negative number means infinity. The default is infinity.\n" \ |
90 | "\n" \ |
93 | "\n" \ |
91 | "-f protocol_family | --family=protocol_family\n" \ |
94 | "-f protocol_family | --family=protocol_family\n" \ |
92 | "\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n" |
95 | "\tThe listenning socket protocol family. Only the PF_INET and PF_INET6 are supported.\n" |
Line 137... | Line 140... | ||
137 | char * reply = NULL; |
140 | char * reply = NULL; |
138 | sock_type_t type = SOCK_DGRAM; |
141 | sock_type_t type = SOCK_DGRAM; |
139 | int count = -1; |
142 | int count = -1; |
140 | int family = PF_INET; |
143 | int family = PF_INET; |
141 | uint16_t port = 7; |
144 | uint16_t port = 7; |
- | 145 | int backlog = 3; |
|
142 | 146 | ||
143 | socklen_t max_length = sizeof( struct sockaddr_in6 ); |
147 | socklen_t max_length = sizeof( struct sockaddr_in6 ); |
144 | uint8_t address_data[ max_length ]; |
148 | uint8_t address_data[ max_length ]; |
145 | struct sockaddr * address = ( struct sockaddr * ) address_data; |
149 | struct sockaddr * address = ( struct sockaddr * ) address_data; |
146 | struct sockaddr_in * address_in = ( struct sockaddr_in * ) address; |
150 | struct sockaddr_in * address_in = ( struct sockaddr_in * ) address; |
Line 160... | Line 164... | ||
160 | printf( "%s\n", NAME ); |
164 | printf( "%s\n", NAME ); |
161 | 165 | ||
162 | for( index = 1; index < argc; ++ index ){ |
166 | for( index = 1; index < argc; ++ index ){ |
163 | if( argv[ index ][ 0 ] == '-' ){ |
167 | if( argv[ index ][ 0 ] == '-' ){ |
164 | switch( argv[ index ][ 1 ] ){ |
168 | switch( argv[ index ][ 1 ] ){ |
- | 169 | case 'b': ERROR_PROPAGATE( parse_parameter_int( argc, argv, & index, & backlog, "accepted sockets queue size", 0 )); |
|
- | 170 | break; |
|
165 | case 'c': ERROR_PROPAGATE( parse_parameter_int( argc, argv, & index, & count, "message count", 0 )); |
171 | case 'c': ERROR_PROPAGATE( parse_parameter_int( argc, argv, & index, & count, "message count", 0 )); |
166 | break; |
172 | break; |
167 | case 'f': ERROR_PROPAGATE( parse_parameter_name_int( argc, argv, & index, & family, "protocol family", 0, parse_protocol_family )); |
173 | case 'f': ERROR_PROPAGATE( parse_parameter_name_int( argc, argv, & index, & family, "protocol family", 0, parse_protocol_family )); |
168 | break; |
174 | break; |
169 | case 'h': print_help(); |
175 | case 'h': print_help(); |
Line 180... | Line 186... | ||
180 | case 't': ERROR_PROPAGATE( parse_parameter_name_int( argc, argv, & index, & value, "socket type", 0, parse_socket_type )); |
186 | case 't': ERROR_PROPAGATE( parse_parameter_name_int( argc, argv, & index, & value, "socket type", 0, parse_socket_type )); |
181 | type = ( sock_type_t ) value; |
187 | type = ( sock_type_t ) value; |
182 | break; |
188 | break; |
183 | case 'v': verbose = 1; |
189 | case 'v': verbose = 1; |
184 | break; |
190 | break; |
185 | case '-': if( str_lcmp( argv[ index ] + 2, "count=", 6 ) == 0 ){ |
191 | case '-': if( str_lcmp( argv[ index ] + 2, "backlog=", 6 ) == 0 ){ |
- | 192 | ERROR_PROPAGATE( parse_parameter_int( argc, argv, & index, & backlog, "accepted sockets queue size", 8 )); |
|
- | 193 | }else if( str_lcmp( argv[ index ] + 2, "count=", 6 ) == 0 ){ |
|
186 | ERROR_PROPAGATE( parse_parameter_int( argc, argv, & index, & count, "message count", 8 )); |
194 | ERROR_PROPAGATE( parse_parameter_int( argc, argv, & index, & count, "message count", 8 )); |
187 | }else if( str_lcmp( argv[ index ] + 2, "family=", 7 ) == 0 ){ |
195 | }else if( str_lcmp( argv[ index ] + 2, "family=", 7 ) == 0 ){ |
188 | ERROR_PROPAGATE( parse_parameter_name_int( argc, argv, & index, & family, "protocol family", 9, parse_protocol_family )); |
196 | ERROR_PROPAGATE( parse_parameter_name_int( argc, argv, & index, & family, "protocol family", 9, parse_protocol_family )); |
189 | }else if( str_lcmp( argv[ index ] + 2, "help", 5 ) == 0 ){ |
197 | }else if( str_lcmp( argv[ index ] + 2, "help", 5 ) == 0 ){ |
190 | print_help(); |
198 | print_help(); |
Line 261... | Line 269... | ||
261 | socket_print_error( stderr, listening_id, "Socket create: ", "\n" ); |
269 | socket_print_error( stderr, listening_id, "Socket create: ", "\n" ); |
262 | return listening_id; |
270 | return listening_id; |
263 | } |
271 | } |
264 | 272 | ||
265 | if( type == SOCK_STREAM ){ |
273 | if( type == SOCK_STREAM ){ |
- | 274 | if( backlog <= 0 ){ |
|
- | 275 | fprintf( stderr, "Accepted sockets queue size too small (%d). Using 3 instead.\n", size ); |
|
- | 276 | backlog = 3; |
|
- | 277 | } |
|
266 | if( ERROR_OCCURRED( listen( listening_id, 3 ))){ |
278 | if( ERROR_OCCURRED( listen( listening_id, backlog ))){ |
267 | socket_print_error( stderr, ERROR_CODE, "Socket listen: ", "\n" ); |
279 | socket_print_error( stderr, ERROR_CODE, "Socket listen: ", "\n" ); |
268 | return ERROR_CODE; |
280 | return ERROR_CODE; |
269 | } |
281 | } |
270 | } |
282 | } |
271 | 283 |