Changeset b5cf742a in mainline
- Timestamp:
- 2013-06-28T16:22:42Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- edf0d27
- Parents:
- e52b4b5
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest1/nettest1.c
re52b4b5 rb5cf742a 54 54 55 55 /** Echo module name. */ 56 #define NAME "Nettest1"56 #define NAME "nettest1" 57 57 58 58 /** Packet data pattern. */ 59 #define NETTEST1_TEXT 59 #define NETTEST1_TEXT "Networking test 1 - sockets" 60 60 61 61 static int family = PF_INET; … … 114 114 int value; 115 115 int rc; 116 116 117 117 switch (argv[*index][1]) { 118 118 /* … … 120 120 */ 121 121 case 'f': 122 rc = arg_parse_name_int(argc, argv, index, &family, 0, socket_parse_protocol_family); 123 if (rc != EOK) 124 return rc; 122 rc = arg_parse_name_int(argc, argv, index, &value, 0, 123 socket_parse_protocol_family); 124 if (rc != EOK) 125 return rc; 126 127 family = (uint16_t) value; 125 128 break; 126 129 case 'h': … … 131 134 if (rc != EOK) 132 135 return rc; 136 133 137 break; 134 138 case 'n': … … 136 140 if (rc != EOK) 137 141 return rc; 142 138 143 break; 139 144 case 'p': … … 141 146 if (rc != EOK) 142 147 return rc; 148 143 149 port = (uint16_t) value; 144 150 break; … … 147 153 if (rc != EOK) 148 154 return rc; 155 149 156 size = (value >= 0) ? (size_t) value : 0; 150 157 break; 151 158 case 't': 152 rc = arg_parse_name_int(argc, argv, index, &value, 0, socket_parse_socket_type); 153 if (rc != EOK) 154 return rc; 159 rc = arg_parse_name_int(argc, argv, index, &value, 0, 160 socket_parse_socket_type); 161 if (rc != EOK) 162 return rc; 163 155 164 type = (sock_type_t) value; 156 165 break; … … 158 167 verbose = 1; 159 168 break; 169 160 170 /* 161 171 * Long options with double dash ('-') … … 163 173 case '-': 164 174 if (str_lcmp(argv[*index] + 2, "family=", 7) == 0) { 165 rc = arg_parse_name_int(argc, argv, index, & family, 9,175 rc = arg_parse_name_int(argc, argv, index, &value, 9, 166 176 socket_parse_protocol_family); 167 177 if (rc != EOK) 168 178 return rc; 179 180 family = (uint16_t) value; 169 181 } else if (str_lcmp(argv[*index] + 2, "help", 5) == 0) { 170 182 nettest1_print_help(); … … 182 194 if (rc != EOK) 183 195 return rc; 196 184 197 port = (uint16_t) value; 185 198 } else if (str_lcmp(argv[*index] + 2, "type=", 5) == 0) { … … 188 201 if (rc != EOK) 189 202 return rc; 203 190 204 type = (sock_type_t) value; 191 205 } else if (str_lcmp(argv[*index] + 2, "verbose", 8) == 0) { … … 200 214 return EINVAL; 201 215 } 202 216 203 217 return EOK; 204 218 } … … 211 225 static void nettest1_fill_buffer(char *buffer, size_t size) 212 226 { 213 size_t length; 214 215 length = 0; 227 size_t length = 0; 216 228 while (size > length + sizeof(NETTEST1_TEXT) - 1) { 217 229 memcpy(buffer + length, NETTEST1_TEXT, … … 219 231 length += sizeof(NETTEST1_TEXT) - 1; 220 232 } 221 233 222 234 memcpy(buffer + length, NETTEST1_TEXT, size - length); 223 235 buffer[size] = '\0'; … … 226 238 static int nettest1_test(int *socket_ids, int nsockets, int nmessages) 227 239 { 228 int rc;229 230 240 if (verbose) 231 241 printf("%d sockets, %d messages\n", nsockets, nmessages); 232 233 rc = sockets_create(verbose, socket_ids, nsockets, family, type);234 if (rc != EOK) 235 return rc; 236 242 243 int rc = sockets_create(verbose, socket_ids, nsockets, family, type); 244 if (rc != EOK) 245 return rc; 246 237 247 if (type == SOCK_STREAM) { 238 248 rc = sockets_connect(verbose, socket_ids, nsockets, address, … … 241 251 return rc; 242 252 } 243 253 244 254 rc = sockets_sendto_recvfrom(verbose, socket_ids, nsockets, address, 245 255 &addrlen, data, size, nmessages); 246 256 if (rc != EOK) 247 257 return rc; 248 258 249 259 rc = sockets_close(verbose, socket_ids, nsockets); 250 260 if (rc != EOK) 251 261 return rc; 252 262 253 263 if (verbose) 254 264 printf("\tOK\n"); 255 265 256 266 /****/ 257 267 258 268 rc = sockets_create(verbose, socket_ids, nsockets, family, type); 259 269 if (rc != EOK) 260 270 return rc; 261 271 262 272 if (type == SOCK_STREAM) { 263 273 rc = sockets_connect(verbose, socket_ids, nsockets, address, … … 266 276 return rc; 267 277 } 268 278 269 279 rc = sockets_sendto(verbose, socket_ids, nsockets, address, addrlen, 270 280 data, size, nmessages); 271 281 if (rc != EOK) 272 282 return rc; 273 283 274 284 rc = sockets_recvfrom(verbose, socket_ids, nsockets, address, &addrlen, 275 285 data, size, nmessages); 276 286 if (rc != EOK) 277 287 return rc; 278 288 279 289 rc = sockets_close(verbose, socket_ids, nsockets); 280 290 if (rc != EOK) 281 291 return rc; 282 292 283 293 if (verbose) 284 294 printf("\tOK\n"); 285 295 286 296 return EOK; 287 297 } … … 320 330 } 321 331 } 322 332 323 333 /* If not before the last argument containing the host */ 324 334 if (index >= argc) { … … 366 376 } 367 377 } 368 378 369 379 /* Check data buffer size */ 370 380 if (size <= 0) { … … 373 383 size = 1024; 374 384 } 375 385 376 386 /* 377 387 * Prepare data buffer. Allocate size bytes plus one for the … … 384 394 } 385 395 nettest1_fill_buffer(data, size); 386 396 387 397 /* Check socket count */ 388 398 if (sockets <= 0) { … … 391 401 sockets = 2; 392 402 } 393 403 394 404 /* 395 405 * Prepare socket buffer. Allocate count fields plus the terminating … … 401 411 return ENOMEM; 402 412 } 413 403 414 socket_ids[sockets] = 0; 404 415 405 416 if (verbose) 406 417 printf("Starting tests\n"); 407 418 408 419 rc = gettimeofday(&time_before, NULL); 409 420 if (rc != EOK) { … … 411 422 return rc; 412 423 } 413 424 414 425 nettest1_test(socket_ids, 1, 1); 415 426 nettest1_test(socket_ids, 1, messages); 416 427 nettest1_test(socket_ids, sockets, 1); 417 428 nettest1_test(socket_ids, sockets, messages); 418 429 419 430 rc = gettimeofday(&time_after, NULL); 420 431 if (rc != EOK) { … … 422 433 return rc; 423 434 } 424 435 425 436 printf("Tested in %ld microseconds\n", tv_sub(&time_after, 426 437 &time_before)); 427 438 428 439 if (verbose) 429 440 printf("Exiting\n"); 430 441 431 442 return EOK; 432 443 } 433 444 434 435 445 /** @} 436 446 */ -
uspace/app/nettest2/nettest2.c
re52b4b5 rb5cf742a 55 55 56 56 /** Echo module name. */ 57 #define NAME "Nettest2"57 #define NAME "nettest2" 58 58 59 59 /** Packet data pattern. */ 60 #define NETTEST2_TEXT 60 #define NETTEST2_TEXT "Networking test 2 - transfer" 61 61 62 62 static size_t size; … … 107 107 static void nettest2_fill_buffer(char *buffer, size_t size) 108 108 { 109 size_t length; 110 111 length = 0; 109 size_t length = 0; 112 110 while (size > length + sizeof(NETTEST2_TEXT) - 1) { 113 111 memcpy(buffer + length, NETTEST2_TEXT, … … 115 113 length += sizeof(NETTEST2_TEXT) - 1; 116 114 } 117 115 118 116 memcpy(buffer + length, NETTEST2_TEXT, size - length); 119 117 buffer[size] = '\0'; … … 130 128 int value; 131 129 int rc; 132 130 133 131 switch (argv[*index][1]) { 134 132 /* … … 136 134 */ 137 135 case 'f': 138 rc = arg_parse_name_int(argc, argv, index, & family, 0,136 rc = arg_parse_name_int(argc, argv, index, &value, 0, 139 137 socket_parse_protocol_family); 140 138 if (rc != EOK) 141 139 return rc; 140 141 family = (uint16_t) value; 142 142 break; 143 143 case 'h': 144 144 nettest2_print_help(); 145 145 return EOK; 146 break;147 146 case 'm': 148 147 rc = arg_parse_int(argc, argv, index, &messages, 0); 149 148 if (rc != EOK) 150 149 return rc; 150 151 151 break; 152 152 case 'n': … … 154 154 if (rc != EOK) 155 155 return rc; 156 156 157 break; 157 158 case 'p': … … 159 160 if (rc != EOK) 160 161 return rc; 162 161 163 port = (uint16_t) value; 162 164 break; … … 165 167 if (rc != EOK) 166 168 return rc; 169 167 170 size = (value >= 0) ? (size_t) value : 0; 168 171 break; … … 172 175 if (rc != EOK) 173 176 return rc; 177 174 178 type = (sock_type_t) value; 175 179 break; … … 177 181 verbose = true; 178 182 break; 183 179 184 /* 180 185 * Long options with double dash ('-') … … 182 187 case '-': 183 188 if (str_lcmp(argv[*index] + 2, "family=", 7) == 0) { 184 rc = arg_parse_name_int(argc, argv, index, & family, 9,189 rc = arg_parse_name_int(argc, argv, index, &value, 9, 185 190 socket_parse_protocol_family); 186 191 if (rc != EOK) 187 192 return rc; 193 194 family = (uint16_t) value; 188 195 } else if (str_lcmp(argv[*index] + 2, "help", 5) == 0) { 189 196 nettest2_print_help(); … … 201 208 if (rc != EOK) 202 209 return rc; 210 203 211 port = (uint16_t) value; 204 212 } else if (str_lcmp(argv[*index] + 2, "type=", 5) == 0) { … … 207 215 if (rc != EOK) 208 216 return rc; 217 209 218 type = (sock_type_t) value; 210 219 } else if (str_lcmp(argv[*index] + 2, "verbose", 8) == 0) { … … 219 228 return EINVAL; 220 229 } 221 230 222 231 return EOK; 223 232 } … … 266 275 } 267 276 } 268 277 269 278 /* If not before the last argument containing the host */ 270 279 if (index >= argc) { … … 312 321 } 313 322 } 314 323 315 324 /* Check data buffer size. */ 316 325 if (size <= 0) { … … 319 328 size = 1024; 320 329 } 321 330 322 331 /* 323 332 * Prepare the buffer. Allocate size bytes plus one for terminating … … 329 338 return ENOMEM; 330 339 } 331 340 332 341 /* Fill buffer with a pattern. */ 333 342 nettest2_fill_buffer(data, size); 334 343 335 344 /* Check socket count. */ 336 345 if (sockets <= 0) { … … 339 348 sockets = 2; 340 349 } 341 350 342 351 /* 343 352 * Prepare the socket buffer. … … 350 359 } 351 360 socket_ids[sockets] = 0; 352 361 353 362 if (verbose) 354 363 printf("Starting tests\n"); 355 364 356 365 rc = sockets_create(verbose, socket_ids, sockets, family, type); 357 366 if (rc != EOK) 358 367 return rc; 359 368 360 369 if (type == SOCK_STREAM) { 361 370 rc = sockets_connect(verbose, socket_ids, sockets, … … 364 373 return rc; 365 374 } 366 375 367 376 if (verbose) 368 377 printf("\n"); 369 378 370 379 rc = gettimeofday(&time_before, NULL); 371 380 if (rc != EOK) { … … 373 382 return rc; 374 383 } 375 384 376 385 rc = sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, 377 386 &addrlen, data, size, messages); 378 387 if (rc != EOK) 379 388 return rc; 380 389 381 390 rc = gettimeofday(&time_after, NULL); 382 391 if (rc != EOK) { … … 384 393 return rc; 385 394 } 386 395 387 396 if (verbose) 388 397 printf("\tOK\n"); 389 398 390 399 printf("sendto + recvfrom tested in %ld microseconds\n", 391 400 tv_sub(&time_after, &time_before)); 392 401 393 402 rc = gettimeofday(&time_before, NULL); 394 403 if (rc != EOK) { … … 396 405 return rc; 397 406 } 398 407 399 408 rc = sockets_sendto(verbose, socket_ids, sockets, address, addrlen, 400 409 data, size, messages); 401 410 if (rc != EOK) 402 411 return rc; 403 412 404 413 rc = sockets_recvfrom(verbose, socket_ids, sockets, address, &addrlen, 405 414 data, size, messages); 406 415 if (rc != EOK) 407 416 return rc; 408 417 409 418 rc = gettimeofday(&time_after, NULL); 410 419 if (rc != EOK) { … … 412 421 return rc; 413 422 } 414 423 415 424 if (verbose) 416 425 printf("\tOK\n"); 417 426 418 427 printf("sendto, recvfrom tested in %ld microseconds\n", 419 428 tv_sub(&time_after, &time_before)); 420 429 421 430 rc = sockets_close(verbose, socket_ids, sockets); 422 431 if (rc != EOK) 423 432 return rc; 424 433 425 434 if (verbose) 426 435 printf("\nExiting\n"); 427 436 428 437 return EOK; 429 438 } -
uspace/app/nterm/conn.c
re52b4b5 rb5cf742a 103 103 goto error; 104 104 } 105 105 106 106 conn_fd = socket(PF_INET, SOCK_STREAM, 0); 107 107 if (conn_fd < 0) 108 108 goto error; 109 109 110 110 printf("Connecting to host %s port %u\n", addr_s, ntohs(addr.sin_port)); 111 111 112 112 rc = connect(conn_fd, (struct sockaddr *)&addr, sizeof(addr)); 113 113 if (rc != EOK) 114 114 goto error; 115 115 116 116 rcv_fid = fibril_create(rcv_fibril, NULL); 117 117 if (rcv_fid == 0) 118 118 goto error; 119 119 120 120 fibril_add_ready(rcv_fid); 121 121 122 122 return EOK; 123 123 124 124 error: 125 125 if (conn_fd >= 0) { … … 127 127 conn_fd = -1; 128 128 } 129 129 130 130 return EIO; 131 131 } … … 133 133 int conn_send(void *data, size_t size) 134 134 { 135 int rc; 136 137 rc = send(conn_fd, data, size, 0); 135 int rc = send(conn_fd, data, size, 0); 138 136 if (rc != EOK) 139 137 return EIO; 140 138 141 139 return EOK; 142 140 } -
uspace/lib/c/generic/inet.c
re52b4b5 rb5cf742a 169 169 inet_addr_unpack(IPC_GET_ARG2(*call), &dgram.dest); 170 170 dgram.tos = IPC_GET_ARG3(*call); 171 171 172 172 rc = async_data_write_accept(&dgram.data, false, 0, 0, 0, &dgram.size); 173 173 if (rc != EOK) { … … 175 175 return; 176 176 } 177 177 178 178 rc = inet_ev_ops->recv(&dgram); 179 179 async_answer_0(callid, rc); … … 185 185 ipc_call_t call; 186 186 ipc_callid_t callid = async_get_call(&call); 187 187 188 188 if (!IPC_GET_IMETHOD(call)) { 189 189 /* TODO: Handle hangup */ 190 190 return; 191 191 } 192 192 193 193 switch (IPC_GET_IMETHOD(call)) { 194 194 case INET_EV_RECV: -
uspace/lib/c/generic/inetcfg.c
re52b4b5 rb5cf742a 159 159 *addr_id = IPC_GET_ARG1(answer); 160 160 161 return retval;161 return (int) retval; 162 162 } 163 163 … … 178 178 size_t act_size; 179 179 char name_buf[LOC_NAME_MAXLEN + 1]; 180 181 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 182 180 181 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 182 183 183 ipc_call_t answer; 184 184 aid_t req = async_send_1(exch, INETCFG_ADDR_GET, addr_id, &answer); 185 185 aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply); 186 186 async_wait_for(dreq, &dretval); 187 188 async_exchange_end(exch); 189 187 188 async_exchange_end(exch); 189 190 190 if (dretval != EOK) { 191 191 async_forget(req); 192 192 return dretval; 193 193 } 194 194 195 195 sysarg_t retval; 196 196 async_wait_for(req, &retval); 197 197 198 198 if (retval != EOK) 199 return retval;200 199 return (int) retval; 200 201 201 act_size = IPC_GET_ARG2(dreply); 202 202 assert(act_size <= LOC_NAME_MAXLEN); 203 203 204 name_buf[act_size] = '\0'; 204 205 … … 207 208 ainfo->ilink = IPC_GET_ARG3(answer); 208 209 ainfo->name = str_dup(name_buf); 209 210 210 211 return EOK; 211 212 } … … 340 341 341 342 async_exch_t *exch = async_exchange_begin(inetcfg_sess); 342 343 343 344 ipc_call_t answer; 344 345 aid_t req = async_send_1(exch, INETCFG_SROUTE_GET, sroute_id, &answer); 345 346 aid_t dreq = async_data_read(exch, name_buf, LOC_NAME_MAXLEN, &dreply); 346 347 async_wait_for(dreq, &dretval); 347 348 async_exchange_end(exch); 349 348 349 async_exchange_end(exch); 350 350 351 if (dretval != EOK) { 351 352 async_forget(req); 352 353 return dretval; 353 354 } 354 355 355 356 sysarg_t retval; 356 357 async_wait_for(req, &retval); 357 358 358 359 if (retval != EOK) 359 return retval;360 360 return (int) retval; 361 361 362 act_size = IPC_GET_ARG2(dreply); 362 363 assert(act_size <= LOC_NAME_MAXLEN); … … 367 368 inet_addr_unpack(IPC_GET_ARG3(answer), &srinfo->router); 368 369 srinfo->name = str_dup(name_buf); 369 370 370 371 return EOK; 371 372 } -
uspace/lib/c/generic/iplink.c
re52b4b5 rb5cf742a 99 99 sysarg_t retval; 100 100 async_wait_for(req, &retval); 101 if (retval != EOK)102 return retval;103 101 104 return EOK;102 return (int) retval; 105 103 } 106 104 … … 169 167 static void iplink_cb_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg) 170 168 { 171 iplink_t *iplink = (iplink_t *) arg;172 169 iplink_t *iplink = (iplink_t *) arg; 170 173 171 while (true) { 174 172 ipc_call_t call; 175 173 ipc_callid_t callid = async_get_call(&call); 176 174 177 175 if (!IPC_GET_IMETHOD(call)) { 178 176 /* TODO: Handle hangup */ 179 177 return; 180 178 } 181 179 182 180 switch (IPC_GET_IMETHOD(call)) { 183 181 case IPLINK_EV_RECV: -
uspace/lib/c/generic/iplink_srv.c
re52b4b5 rb5cf742a 44 44 ipc_call_t *call) 45 45 { 46 int rc;47 46 size_t mtu; 48 49 rc = srv->ops->get_mtu(srv, &mtu); 47 int rc = srv->ops->get_mtu(srv, &mtu); 50 48 async_answer_1(callid, rc, mtu); 51 49 } … … 70 68 iplink_srv_sdu_t sdu; 71 69 int rc; 72 70 73 71 sdu.lsrc = IPC_GET_ARG1(*call); 74 72 sdu.ldest = IPC_GET_ARG2(*call); 75 73 76 74 rc = async_data_write_accept(&sdu.data, false, 0, 0, 0, &sdu.size); 77 75 if (rc != EOK) { … … 79 77 return; 80 78 } 81 79 82 80 rc = srv->ops->send(srv, &sdu); 83 81 free(sdu.data); … … 98 96 iplink_srv_t *srv = (iplink_srv_t *)arg; 99 97 int rc; 100 98 101 99 fibril_mutex_lock(&srv->lock); 102 100 if (srv->connected) { … … 105 103 return EBUSY; 106 104 } 107 105 108 106 srv->connected = true; 109 107 fibril_mutex_unlock(&srv->lock); 110 108 111 109 /* Accept the connection */ 112 110 async_answer_0(iid, EOK); 113 111 114 112 async_sess_t *sess = async_callback_receive(EXCHANGE_SERIALIZE); 115 113 if (sess == NULL) 116 114 return ENOMEM; 117 115 118 116 srv->client_sess = sess; 119 117 120 118 rc = srv->ops->open(srv); 121 119 if (rc != EOK) 122 120 return rc; 123 121 124 122 while (true) { 125 123 ipc_call_t call; 126 124 ipc_callid_t callid = async_get_call(&call); 127 125 sysarg_t method = IPC_GET_IMETHOD(call); 128 126 129 127 if (!method) { 130 128 /* The other side has hung up */ … … 135 133 break; 136 134 } 137 135 138 136 switch (method) { 139 137 case IPLINK_GET_MTU: … … 153 151 } 154 152 } 155 153 156 154 return srv->ops->close(srv); 157 155 } … … 161 159 if (srv->client_sess == NULL) 162 160 return EIO; 163 161 164 162 async_exch_t *exch = async_exchange_begin(srv->client_sess); 165 163 166 164 ipc_call_t answer; 167 165 aid_t req = async_send_2(exch, IPLINK_EV_RECV, (sysarg_t) sdu->lsrc, … … 169 167 int rc = async_data_write_start(exch, sdu->data, sdu->size); 170 168 async_exchange_end(exch); 171 169 172 170 if (rc != EOK) { 173 171 async_forget(req); 174 172 return rc; 175 173 } 176 174 177 175 sysarg_t retval; 178 176 async_wait_for(req, &retval); 179 177 if (retval != EOK) 180 178 return retval; 181 179 182 180 return EOK; 183 181 }
Note:
See TracChangeset
for help on using the changeset viewer.