Changes in uspace/app/nettest1/nettest.c [0bbef9b:d9e2e0e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/nettest1/nettest.c
r0bbef9b 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 37 37 #include <stdio.h> 38 #include <err.h> 39 38 40 #include <net/socket.h> 39 41 … … 41 43 #include "print_error.h" 42 44 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) 45 int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){ 46 int index; 47 48 if(verbose){ 59 49 printf("Create\t"); 60 61 fflush(stdout); 62 63 for (index = 0; index < sockets; index++) { 50 } 51 fflush(stdout); 52 for(index = 0; index < sockets; ++ index){ 64 53 socket_ids[index] = socket(family, type, 0); 65 if (socket_ids[index] < 0){54 if(socket_ids[index] < 0){ 66 55 printf("Socket %d (%d) error:\n", index, socket_ids[index]); 67 56 socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n"); 68 57 return socket_ids[index]; 69 58 } 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) 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){ 91 72 printf("\tClose\t"); 92 93 fflush(stdout); 94 95 for (index = 0; index < sockets; index++) { 96 rc = closesocket(socket_ids[index]); 97 if (rc != EOK) { 73 } 74 fflush(stdout); 75 for(index = 0; index < sockets; ++ index){ 76 if(ERROR_OCCURRED(closesocket(socket_ids[index]))){ 98 77 printf("Socket %d (%d) error:\n", index, socket_ids[index]); 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) 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){ 125 94 printf("\tConnect\t"); 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 { 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 157 112 int index; 158 113 int message; 159 int rc; 160 161 if (verbose) 114 115 if(verbose){ 162 116 printf("\tSendto\t"); 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 { 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){ 197 135 int value; 198 136 int index; 199 137 int message; 200 138 201 if (verbose)139 if(verbose){ 202 140 printf("\tRecvfrom\t"); 203 204 fflush(stdout); 205 206 for (index = 0; index < sockets; index++) { 207 for (message = 0; message < messages; message++) { 141 } 142 fflush(stdout); 143 for(index = 0; index < sockets; ++ index){ 144 for(message = 0; message < messages; ++ message){ 208 145 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 209 if (value < 0){146 if(value < 0){ 210 147 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 211 148 socket_print_error(stderr, value, "Socket receive: ", "\n"); … … 213 150 } 214 151 } 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 { 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 239 162 int value; 240 163 int index; 241 164 int message; 242 int rc; 243 244 if (verbose) 165 166 if(verbose){ 245 167 printf("\tSendto and recvfrom\t"); 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; 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; 256 176 } 257 177 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 258 if (value < 0){178 if(value < 0){ 259 179 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 260 180 socket_print_error(stderr, value, "Socket receive: ", "\n"); … … 262 182 } 263 183 } 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) 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){ 280 193 printf("*"); 281 else194 }else{ 282 195 printf("|"); 196 } 283 197 fflush(stdout); 284 198 }
Note:
See TracChangeset
for help on using the changeset viewer.