Changes in uspace/app/nettest1/nettest.c [d9e2e0e:0bbef9b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest1/nettest.c
rd9e2e0e r0bbef9b 28 28 29 29 /** @addtogroup nettest 30 * 30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * 34 * Networking test support functions implementation. 35 35 */ 36 36 37 37 #include <stdio.h> 38 #include <err.h>39 40 38 #include <net/socket.h> 41 39 … … 43 41 #include "print_error.h" 44 42 45 int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){ 46 int index; 47 48 if(verbose){ 43 44 /** Creates new sockets. 45 * 46 * @param[in] verbose A value indicating whether to print out verbose information. 47 * @param[out] socket_ids A field to store the socket identifiers. 48 * @param[in] sockets The number of sockets to create. Should be at most the size of the field. 49 * @param[in] family The socket address family. 50 * @param[in] type The socket type. 51 * @returns EOK on success. 52 * @returns Other error codes as defined for the socket() function. 53 */ 54 int sockets_create(int verbose, int *socket_ids, int sockets, int family, sock_type_t type) 55 { 56 int index; 57 58 if (verbose) 49 59 printf("Create\t"); 50 } 51 fflush(stdout); 52 for(index = 0; index < sockets; ++ index){ 60 61 fflush(stdout); 62 63 for (index = 0; index < sockets; index++) { 53 64 socket_ids[index] = socket(family, type, 0); 54 if (socket_ids[index] < 0){65 if (socket_ids[index] < 0) { 55 66 printf("Socket %d (%d) error:\n", index, socket_ids[index]); 56 67 socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n"); 57 68 return socket_ids[index]; 58 69 } 59 if(verbose){ 60 print_mark(index); 61 } 62 } 63 return EOK; 64 } 65 66 int sockets_close(int verbose, int * socket_ids, int sockets){ 67 ERROR_DECLARE; 68 69 int index; 70 71 if(verbose){ 70 if (verbose) 71 print_mark(index); 72 } 73 74 return EOK; 75 } 76 77 /** Closes sockets. 78 * 79 * @param[in] verbose A value indicating whether to print out verbose information. 80 * @param[in] socket_ids A field of stored socket identifiers. 81 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field. 82 * @returns EOK on success. 83 * @returns Other error codes as defined for the closesocket() function. 84 */ 85 int sockets_close(int verbose, int *socket_ids, int sockets) 86 { 87 int index; 88 int rc; 89 90 if (verbose) 72 91 printf("\tClose\t"); 73 } 74 fflush(stdout); 75 for(index = 0; index < sockets; ++ index){ 76 if(ERROR_OCCURRED(closesocket(socket_ids[index]))){ 92 93 fflush(stdout); 94 95 for (index = 0; index < sockets; index++) { 96 rc = closesocket(socket_ids[index]); 97 if (rc != EOK) { 77 98 printf("Socket %d (%d) error:\n", index, socket_ids[index]); 78 socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n"); 79 return ERROR_CODE; 80 } 81 if(verbose){ 82 print_mark(index); 83 } 84 } 85 return EOK; 86 } 87 88 int sockets_connect(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen){ 89 ERROR_DECLARE; 90 91 int index; 92 93 if(verbose){ 99 socket_print_error(stderr, rc, "Socket close: ", "\n"); 100 return rc; 101 } 102 if (verbose) 103 print_mark(index); 104 } 105 106 return EOK; 107 } 108 109 /** Connects sockets. 110 * 111 * @param[in] verbose A value indicating whether to print out verbose information. 112 * @param[in] socket_ids A field of stored socket identifiers. 113 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field. 114 * @param[in] address The destination host address to connect to. 115 * @param[in] addrlen The length of the destination address in bytes. 116 * @returns EOK on success. 117 * @returns Other error codes as defined for the connect() function. 118 */ 119 int sockets_connect(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen) 120 { 121 int index; 122 int rc; 123 124 if (verbose) 94 125 printf("\tConnect\t"); 95 } 96 fflush(stdout); 97 for(index = 0; index < sockets; ++ index){ 98 if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){ 99 socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n"); 100 return ERROR_CODE; 101 } 102 if(verbose){ 103 print_mark(index); 104 } 105 } 106 return EOK; 107 } 108 109 int sockets_sendto(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t addrlen, char * data, int size, int messages){ 110 ERROR_DECLARE; 111 126 127 fflush(stdout); 128 129 for (index = 0; index < sockets; index++) { 130 rc = connect(socket_ids[index], address, addrlen); 131 if (rc != EOK) { 132 socket_print_error(stderr, rc, "Socket connect: ", "\n"); 133 return rc; 134 } 135 if (verbose) 136 print_mark(index); 137 } 138 139 return EOK; 140 } 141 142 /** Sends data via sockets. 143 * 144 * @param[in] verbose A value indicating whether to print out verbose information. 145 * @param[in] socket_ids A field of stored socket identifiers. 146 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field. 147 * @param[in] address The destination host address to send data to. 148 * @param[in] addrlen The length of the destination address in bytes. 149 * @param[in] data The data to be sent. 150 * @param[in] size The data size in bytes. 151 * @param[in] messages The number of datagrams per socket to be sent. 152 * @returns EOK on success. 153 * @returns Other error codes as defined for the sendto() function. 154 */ 155 int sockets_sendto(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen, char *data, int size, int messages) 156 { 112 157 int index; 113 158 int message; 114 115 if(verbose){ 159 int rc; 160 161 if (verbose) 116 162 printf("\tSendto\t"); 117 } 118 fflush(stdout); 119 for(index = 0; index < sockets; ++ index){ 120 for(message = 0; message < messages; ++ message){ 121 if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, addrlen))){ 122 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 123 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); 124 return ERROR_CODE; 125 } 126 } 127 if(verbose){ 128 print_mark(index); 129 } 130 } 131 return EOK; 132 } 133 134 int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){ 163 164 fflush(stdout); 165 166 for (index = 0; index < sockets; index++) { 167 for (message = 0; message < messages; message++) { 168 rc = sendto(socket_ids[index], data, size, 0, address, addrlen); 169 if (rc != EOK) { 170 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 171 socket_print_error(stderr, rc, "Socket send: ", "\n"); 172 return rc; 173 } 174 } 175 if (verbose) 176 print_mark(index); 177 } 178 179 return EOK; 180 } 181 182 /** Receives data via sockets. 183 * 184 * @param[in] verbose A value indicating whether to print out verbose information. 185 * @param[in] socket_ids A field of stored socket identifiers. 186 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field. 187 * @param[in] address The source host address of received datagrams. 188 * @param[in,out] addrlen The maximum length of the source address in bytes. The actual size of the source address is set instead. 189 * @param[out] data The received data. 190 * @param[in] size The maximum data size in bytes. 191 * @param[in] messages The number of datagrams per socket to be received. 192 * @returns EOK on success. 193 * @returns Other error codes as defined for the recvfrom() function. 194 */ 195 int sockets_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages) 196 { 135 197 int value; 136 198 int index; 137 199 int message; 138 200 139 if (verbose){201 if (verbose) 140 202 printf("\tRecvfrom\t"); 141 } 142 fflush(stdout); 143 for(index = 0; index < sockets; ++ index){ 144 for(message = 0; message < messages; ++ message){ 203 204 fflush(stdout); 205 206 for (index = 0; index < sockets; index++) { 207 for (message = 0; message < messages; message++) { 145 208 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 146 if (value < 0){209 if (value < 0) { 147 210 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 148 211 socket_print_error(stderr, value, "Socket receive: ", "\n"); … … 150 213 } 151 214 } 152 if(verbose){ 153 print_mark(index); 154 } 155 } 156 return EOK; 157 } 158 159 int sockets_sendto_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){ 160 ERROR_DECLARE; 161 215 if (verbose) 216 print_mark(index); 217 } 218 return EOK; 219 } 220 221 /** Sends and receives data via sockets. 222 * 223 * Each datagram is sent and a reply read consequently. 224 * The next datagram is sent after the reply is received. 225 * 226 * @param[in] verbose A value indicating whether to print out verbose information. 227 * @param[in] socket_ids A field of stored socket identifiers. 228 * @param[in] sockets The number of sockets in the field. Should be at most the size of the field. 229 * @param[in,out] address The destination host address to send data to. The source host address of received datagrams is set instead. 230 * @param[in] addrlen The length of the destination address in bytes. 231 * @param[in,out] data The data to be sent. The received data are set instead. 232 * @param[in] size The data size in bytes. 233 * @param[in] messages The number of datagrams per socket to be received. 234 * @returns EOK on success. 235 * @returns Other error codes as defined for the recvfrom() function. 236 */ 237 int sockets_sendto_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages) 238 { 162 239 int value; 163 240 int index; 164 241 int message; 165 166 if(verbose){ 242 int rc; 243 244 if (verbose) 167 245 printf("\tSendto and recvfrom\t"); 168 } 169 fflush(stdout); 170 for(index = 0; index < sockets; ++ index){ 171 for(message = 0; message < messages; ++ message){ 172 if(ERROR_OCCURRED(sendto(socket_ids[index], data, size, 0, address, * addrlen))){ 173 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 174 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); 175 return ERROR_CODE; 246 247 fflush(stdout); 248 249 for (index = 0; index < sockets; index++) { 250 for (message = 0; message < messages; message++) { 251 rc = sendto(socket_ids[index], data, size, 0, address, *addrlen); 252 if (rc != EOK) { 253 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 254 socket_print_error(stderr, rc, "Socket send: ", "\n"); 255 return rc; 176 256 } 177 257 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 178 if (value < 0){258 if (value < 0) { 179 259 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 180 260 socket_print_error(stderr, value, "Socket receive: ", "\n"); … … 182 262 } 183 263 } 184 if(verbose){ 185 print_mark(index); 186 } 187 } 188 return EOK; 189 } 190 191 void print_mark(int index){ 192 if((index + 1) % 10){ 264 if (verbose) 265 print_mark(index); 266 } 267 268 return EOK; 269 } 270 271 /** Prints a mark. 272 * 273 * If the index is a multiple of ten, a different mark is printed. 274 * 275 * @param[in] index The index of the mark to be printed. 276 */ 277 void print_mark(int index) 278 { 279 if ((index + 1) % 10) 193 280 printf("*"); 194 }else{281 else 195 282 printf("|"); 196 }197 283 fflush(stdout); 198 284 }
Note:
See TracChangeset
for help on using the changeset viewer.