Changes in uspace/app/nettest1/nettest.c [3d459fc:d9e2e0e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest1/nettest.c
r3d459fc rd9e2e0e 28 28 29 29 /** @addtogroup nettest 30 * @{30 * @{ 31 31 */ 32 32 33 33 /** @file 34 * Networking test support functions implementation.34 * Networking test support functions implementation. 35 35 */ 36 36 … … 43 43 #include "print_error.h" 44 44 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) 45 int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){ 46 int index; 47 48 if(verbose){ 61 49 printf("Create\t"); 62 63 fflush(stdout); 64 65 for (index = 0; index < sockets; index++) { 50 } 51 fflush(stdout); 52 for(index = 0; index < sockets; ++ index){ 66 53 socket_ids[index] = socket(family, type, 0); 67 if (socket_ids[index] < 0){54 if(socket_ids[index] < 0){ 68 55 printf("Socket %d (%d) error:\n", index, socket_ids[index]); 69 56 socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n"); 70 57 return socket_ids[index]; 71 58 } 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) 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){ 94 72 printf("\tClose\t"); 95 96 fflush(stdout); 97 98 for (index = 0; index < sockets; index++) { 99 if (ERROR_OCCURRED(closesocket(socket_ids[index]))) { 73 } 74 fflush(stdout); 75 for(index = 0; index < sockets; ++ index){ 76 if(ERROR_OCCURRED(closesocket(socket_ids[index]))){ 100 77 printf("Socket %d (%d) error:\n", index, socket_ids[index]); 101 78 socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n"); 102 79 return ERROR_CODE; 103 80 } 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) 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){ 128 94 printf("\tConnect\t"); 129 130 fflush(stdout); 131 132 for (index = 0; index < sockets; index++) { 133 if (ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))) { 95 } 96 fflush(stdout); 97 for(index = 0; index < sockets; ++ index){ 98 if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){ 134 99 socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n"); 135 100 return ERROR_CODE; 136 101 } 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 { 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){ 159 110 ERROR_DECLARE; 160 111 … … 162 113 int message; 163 114 164 if (verbose)115 if(verbose){ 165 116 printf("\tSendto\t"); 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))) { 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))){ 172 122 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 173 123 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); … … 175 125 } 176 126 } 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 { 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){ 199 135 int value; 200 136 int index; 201 137 int message; 202 138 203 if (verbose)139 if(verbose){ 204 140 printf("\tRecvfrom\t"); 205 206 fflush(stdout); 207 208 for (index = 0; index < sockets; index++) { 209 for (message = 0; message < messages; message++) { 141 } 142 fflush(stdout); 143 for(index = 0; index < sockets; ++ index){ 144 for(message = 0; message < messages; ++ message){ 210 145 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 211 if (value < 0){146 if(value < 0){ 212 147 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 213 148 socket_print_error(stderr, value, "Socket receive: ", "\n"); … … 215 150 } 216 151 } 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 { 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){ 241 160 ERROR_DECLARE; 242 161 … … 245 164 int message; 246 165 247 if (verbose)166 if(verbose){ 248 167 printf("\tSendto and recvfrom\t"); 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))) { 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))){ 255 173 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 256 174 socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n"); … … 258 176 } 259 177 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 260 if (value < 0){178 if(value < 0){ 261 179 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 262 180 socket_print_error(stderr, value, "Socket receive: ", "\n"); … … 264 182 } 265 183 } 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) 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){ 282 193 printf("*"); 283 else194 }else{ 284 195 printf("|"); 196 } 285 197 fflush(stdout); 286 198 }
Note:
See TracChangeset
for help on using the changeset viewer.