Changeset c442f63 in mainline
- Timestamp:
- 2013-07-19T17:38:05Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 65f991e, cb65bbe, cffa14e6
- Parents:
- a5756bc
- Location:
- uspace/app
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/netecho/netecho.c
ra5756bc rc442f63 225 225 uint8_t address_buf[sizeof(struct sockaddr_in6)]; 226 226 227 socklen_t addrlen ;227 socklen_t addrlen = sizeof(struct sockaddr_in6); 228 228 int socket_id; 229 229 ssize_t rcv_size; … … 240 240 if (type == SOCK_STREAM) { 241 241 /* Accept a socket if a stream socket is used */ 242 addrlen = sizeof(address_buf);243 242 if (verbose) 244 243 printf("accept()\n"); … … 280 279 case AF_INET6: 281 280 port = ntohs(address_in6->sin6_port); 282 address_start = (uint8_t *) &address_in6->sin6_addr.s6_addr;281 address_start = (uint8_t *) address_in6->sin6_addr.s6_addr; 283 282 break; 284 283 default: -
uspace/app/nettest1/nettest.c
ra5756bc rc442f63 41 41 #include "print_error.h" 42 42 43 44 43 /** Creates new sockets. 45 44 * … … 52 51 * @return Other error codes as defined for the socket() function. 53 52 */ 54 int sockets_create(int verbose, int *socket_ids, int sockets, int family, sock_type_t type) 55 { 56 int index; 57 53 int sockets_create(int verbose, int *socket_ids, unsigned int sockets, 54 uint16_t family, sock_type_t type) 55 { 58 56 if (verbose) 59 57 printf("Create\t"); 60 61 fflush(stdout); 62 63 for ( index = 0; index < sockets; index++) {58 59 fflush(stdout); 60 61 for (unsigned int index = 0; index < sockets; index++) { 64 62 socket_ids[index] = socket(family, type, 0); 65 63 if (socket_ids[index] < 0) { 66 printf("Socket % d(%d) error:\n", index, socket_ids[index]);64 printf("Socket %u (%d) error:\n", index, socket_ids[index]); 67 65 socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n"); 68 66 return socket_ids[index]; 69 67 } 68 70 69 if (verbose) 71 70 print_mark(index); … … 83 82 * @return Other error codes as defined for the closesocket() function. 84 83 */ 85 int sockets_close(int verbose, int *socket_ids, int sockets) 86 { 87 int index; 88 int rc; 89 84 int sockets_close(int verbose, int *socket_ids, unsigned int sockets) 85 { 90 86 if (verbose) 91 87 printf("\tClose\t"); 92 93 fflush(stdout); 94 95 for ( index = 0; index < sockets; index++) {96 rc = closesocket(socket_ids[index]);88 89 fflush(stdout); 90 91 for (unsigned int index = 0; index < sockets; index++) { 92 int rc = closesocket(socket_ids[index]); 97 93 if (rc != EOK) { 98 printf("Socket % d(%d) error:\n", index, socket_ids[index]);94 printf("Socket %u (%d) error:\n", index, socket_ids[index]); 99 95 socket_print_error(stderr, rc, "Socket close: ", "\n"); 100 96 return rc; 101 97 } 98 102 99 if (verbose) 103 100 print_mark(index); … … 117 114 * @return Other error codes as defined for the connect() function. 118 115 */ 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 116 int sockets_connect(int verbose, int *socket_ids, unsigned int sockets, 117 struct sockaddr *address, socklen_t addrlen) 118 { 124 119 if (verbose) 125 120 printf("\tConnect\t"); … … 127 122 fflush(stdout); 128 123 129 for ( index = 0; index < sockets; index++) {130 rc = connect(socket_ids[index], address, addrlen);124 for (unsigned int index = 0; index < sockets; index++) { 125 int rc = connect(socket_ids[index], address, addrlen); 131 126 if (rc != EOK) { 132 127 socket_print_error(stderr, rc, "Socket connect: ", "\n"); 133 128 return rc; 134 129 } 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. 130 131 if (verbose) 132 print_mark(index); 133 } 134 135 return EOK; 136 } 137 138 /** Send data via sockets. 139 * 140 * @param[in] verbose Print out verbose information. 141 * @param[in] socket_ids Stored socket identifiers. 142 * @param[in] sockets Number of sockets. 143 * @param[in] address Destination host address to send data to. 144 * @param[in] addrlen Length of the destination address in bytes. 145 * @param[in] data Data to be sent. 146 * @param[in] size Size of the data in bytes. 147 * @param[in] messages Number of datagrams per socket to be sent. 148 * @param[in] type Socket type. 149 * 152 150 * @return EOK on success. 153 151 * @return 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 { 157 int index; 158 int message; 159 int rc; 160 152 * 153 */ 154 int sockets_sendto(int verbose, int *socket_ids, unsigned int sockets, 155 struct sockaddr *address, socklen_t addrlen, char *data, size_t size, 156 unsigned int messages, sock_type_t type) 157 { 161 158 if (verbose) 162 159 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); 160 161 fflush(stdout); 162 163 for (unsigned int index = 0; index < sockets; index++) { 164 for (unsigned int message = 0; message < messages; message++) { 165 int rc; 166 167 switch (type) { 168 case SOCK_STREAM: 169 rc = send(socket_ids[index], data, size, 0); 170 break; 171 case SOCK_DGRAM: 172 rc = sendto(socket_ids[index], data, size, 0, address, addrlen); 173 break; 174 default: 175 rc = EINVAL; 176 } 177 169 178 if (rc != EOK) { 170 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 179 printf("Socket %u (%d), message %u error:\n", 180 index, socket_ids[index], message); 171 181 socket_print_error(stderr, rc, "Socket send: ", "\n"); 172 182 return rc; 173 183 } 174 184 } 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. 185 186 if (verbose) 187 print_mark(index); 188 } 189 190 return EOK; 191 } 192 193 /** Receive data via sockets. 194 * 195 * @param[in] verbose Print out verbose information. 196 * @param[in] socket_ids Stored socket identifiers. 197 * @param[in] sockets Number of sockets. 198 * @param[in] address Source host address of received datagrams. 199 * @param[in,out] addrlen Maximum length of the source address in bytes. 200 * The actual size of the source address is set. 201 * @param[out] data Received data. 202 * @param[in] size Maximum data size in bytes. 203 * @param[in] messages Number of datagrams per socket to be received. 204 * 192 205 * @return EOK on success. 193 206 * @return 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 { 197 int value; 198 int index; 199 int message; 200 207 * 208 */ 209 int sockets_recvfrom(int verbose, int *socket_ids, unsigned int sockets, 210 struct sockaddr *address, socklen_t *addrlen, char *data, size_t size, 211 unsigned int messages) 212 { 201 213 if (verbose) 202 214 printf("\tRecvfrom\t"); … … 204 216 fflush(stdout); 205 217 206 for (index = 0; index < sockets; index++) { 207 for (message = 0; message < messages; message++) { 208 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 209 if (value < 0) { 210 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 211 socket_print_error(stderr, value, "Socket receive: ", "\n"); 212 return value; 213 } 214 } 215 if (verbose) 216 print_mark(index); 217 } 218 return EOK; 219 } 220 221 /** Sends and receives data via sockets. 218 for (unsigned int index = 0; index < sockets; index++) { 219 for (unsigned int message = 0; message < messages; message++) { 220 int rc = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 221 if (rc < 0) { 222 printf("Socket %u (%d), message %u error:\n", 223 index, socket_ids[index], message); 224 socket_print_error(stderr, rc, "Socket receive: ", "\n"); 225 return rc; 226 } 227 } 228 229 if (verbose) 230 print_mark(index); 231 } 232 233 return EOK; 234 } 235 236 /** Send and receive data via sockets. 222 237 * 223 238 * Each datagram is sent and a reply read consequently. 224 239 * The next datagram is sent after the reply is received. 225 240 * 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. 241 * @param[in] verbose Print out verbose information. 242 * @param[in] socket_ids Stored socket identifiers. 243 * @param[in] sockets Number of sockets. 244 * @param[in,out] address Destination host address to send data to. 245 * The source host address of received datagrams is set. 246 * @param[in] addrlen Length of the destination address in bytes. 247 * @param[in,out] data Data to be sent. The received data are set. 248 * @param[in] size Size of the data in bytes. 249 * @param[in] messages Number of datagrams per socket to be received. 250 * @param[in] type Socket type. 251 * 234 252 * @return EOK on success. 235 253 * @return 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 { 239 int value; 240 int index; 241 int message; 242 int rc; 243 254 * 255 */ 256 int sockets_sendto_recvfrom(int verbose, int *socket_ids, unsigned int sockets, 257 struct sockaddr *address, socklen_t *addrlen, char *data, 258 size_t size, unsigned int messages, sock_type_t type) 259 { 244 260 if (verbose) 245 261 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); 262 263 fflush(stdout); 264 265 for (unsigned int index = 0; index < sockets; index++) { 266 for (unsigned int message = 0; message < messages; message++) { 267 int rc; 268 269 switch (type) { 270 case SOCK_STREAM: 271 rc = send(socket_ids[index], data, size, 0); 272 break; 273 case SOCK_DGRAM: 274 rc = sendto(socket_ids[index], data, size, 0, address, *addrlen); 275 break; 276 default: 277 rc = EINVAL; 278 } 279 252 280 if (rc != EOK) { 253 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 281 printf("Socket %u (%d), message %u error:\n", 282 index, socket_ids[index], message); 254 283 socket_print_error(stderr, rc, "Socket send: ", "\n"); 255 284 return rc; 256 285 } 257 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 258 if (value < 0) { 259 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message); 260 socket_print_error(stderr, value, "Socket receive: ", "\n"); 261 return value; 262 } 263 } 286 287 rc = recvfrom(socket_ids[index], data, size, 0, address, addrlen); 288 if (rc < 0) { 289 printf("Socket %u (%d), message %u error:\n", 290 index, socket_ids[index], message); 291 socket_print_error(stderr, rc, "Socket receive: ", "\n"); 292 return rc; 293 } 294 } 295 264 296 if (verbose) 265 297 print_mark(index); … … 274 306 * 275 307 * @param[in] index The index of the mark to be printed. 276 */ 277 void print_mark(int index) 308 * 309 */ 310 void print_mark(unsigned int index) 278 311 { 279 312 if ((index + 1) % 10) … … 281 314 else 282 315 printf("|"); 316 283 317 fflush(stdout); 284 318 } -
uspace/app/nettest1/nettest.h
ra5756bc rc442f63 40 40 #include <net/socket.h> 41 41 42 extern void print_mark(int); 43 extern int sockets_create(int, int *, int, int, sock_type_t); 44 extern int sockets_close(int, int *, int); 45 extern int sockets_connect(int, int *, int, struct sockaddr *, socklen_t); 46 extern int sockets_sendto(int, int *, int, struct sockaddr *, socklen_t, char *, int, int); 47 extern int sockets_recvfrom(int, int *, int, struct sockaddr *, socklen_t *, char *, int, int); 48 extern int sockets_sendto_recvfrom(int, int *, int, struct sockaddr *, socklen_t *, char *, int, int); 42 extern void print_mark(unsigned int); 43 extern int sockets_create(int, int *, unsigned int, uint16_t, sock_type_t); 44 extern int sockets_close(int, int *, unsigned int); 45 extern int sockets_connect(int, int *, unsigned int, struct sockaddr *, 46 socklen_t); 47 extern int sockets_sendto(int, int *, unsigned int, struct sockaddr *, 48 socklen_t, char *, size_t, unsigned int, sock_type_t); 49 extern int sockets_recvfrom(int, int *, unsigned int, struct sockaddr *, 50 socklen_t *, char *, size_t, unsigned int); 51 extern int sockets_sendto_recvfrom(int, int *, unsigned int, struct sockaddr *, 52 socklen_t *, char *, size_t, unsigned int, sock_type_t); 49 53 50 54 #endif -
uspace/app/nettest1/nettest1.c
ra5756bc rc442f63 253 253 254 254 rc = sockets_sendto_recvfrom(verbose, socket_ids, nsockets, address, 255 &addrlen, data, size, nmessages );255 &addrlen, data, size, nmessages, type); 256 256 if (rc != EOK) 257 257 return rc; … … 278 278 279 279 rc = sockets_sendto(verbose, socket_ids, nsockets, address, addrlen, 280 data, size, nmessages );280 data, size, nmessages, type); 281 281 if (rc != EOK) 282 282 return rc; -
uspace/app/nettest2/nettest2.c
ra5756bc rc442f63 375 375 376 376 rc = sockets_sendto_recvfrom(verbose, socket_ids, sockets, address, 377 &addrlen, data, size, messages );377 &addrlen, data, size, messages, type); 378 378 if (rc != EOK) 379 379 return rc; … … 399 399 400 400 rc = sockets_sendto(verbose, socket_ids, sockets, address, addrlen, 401 data, size, messages );401 data, size, messages, type); 402 402 if (rc != EOK) 403 403 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.