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