00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00037 #include <stdio.h>
00038 #include <net/socket.h>
00039
00040 #include "nettest.h"
00041 #include "print_error.h"
00042
00043
00054 int sockets_create(int verbose, int *socket_ids, int sockets, int family, sock_type_t type)
00055 {
00056 int index;
00057
00058 if (verbose)
00059 printf("Create\t");
00060
00061 fflush(stdout);
00062
00063 for (index = 0; index < sockets; index++) {
00064 socket_ids[index] = socket(family, type, 0);
00065 if (socket_ids[index] < 0) {
00066 printf("Socket %d (%d) error:\n", index, socket_ids[index]);
00067 socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
00068 return socket_ids[index];
00069 }
00070 if (verbose)
00071 print_mark(index);
00072 }
00073
00074 return EOK;
00075 }
00076
00085 int sockets_close(int verbose, int *socket_ids, int sockets)
00086 {
00087 int index;
00088 int rc;
00089
00090 if (verbose)
00091 printf("\tClose\t");
00092
00093 fflush(stdout);
00094
00095 for (index = 0; index < sockets; index++) {
00096 rc = closesocket(socket_ids[index]);
00097 if (rc != EOK) {
00098 printf("Socket %d (%d) error:\n", index, socket_ids[index]);
00099 socket_print_error(stderr, rc, "Socket close: ", "\n");
00100 return rc;
00101 }
00102 if (verbose)
00103 print_mark(index);
00104 }
00105
00106 return EOK;
00107 }
00108
00119 int sockets_connect(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen)
00120 {
00121 int index;
00122 int rc;
00123
00124 if (verbose)
00125 printf("\tConnect\t");
00126
00127 fflush(stdout);
00128
00129 for (index = 0; index < sockets; index++) {
00130 rc = connect(socket_ids[index], address, addrlen);
00131 if (rc != EOK) {
00132 socket_print_error(stderr, rc, "Socket connect: ", "\n");
00133 return rc;
00134 }
00135 if (verbose)
00136 print_mark(index);
00137 }
00138
00139 return EOK;
00140 }
00141
00155 int sockets_sendto(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen, char *data, int size, int messages)
00156 {
00157 int index;
00158 int message;
00159 int rc;
00160
00161 if (verbose)
00162 printf("\tSendto\t");
00163
00164 fflush(stdout);
00165
00166 for (index = 0; index < sockets; index++) {
00167 for (message = 0; message < messages; message++) {
00168 rc = sendto(socket_ids[index], data, size, 0, address, addrlen);
00169 if (rc != EOK) {
00170 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
00171 socket_print_error(stderr, rc, "Socket send: ", "\n");
00172 return rc;
00173 }
00174 }
00175 if (verbose)
00176 print_mark(index);
00177 }
00178
00179 return EOK;
00180 }
00181
00195 int sockets_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages)
00196 {
00197 int value;
00198 int index;
00199 int message;
00200
00201 if (verbose)
00202 printf("\tRecvfrom\t");
00203
00204 fflush(stdout);
00205
00206 for (index = 0; index < sockets; index++) {
00207 for (message = 0; message < messages; message++) {
00208 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
00209 if (value < 0) {
00210 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
00211 socket_print_error(stderr, value, "Socket receive: ", "\n");
00212 return value;
00213 }
00214 }
00215 if (verbose)
00216 print_mark(index);
00217 }
00218 return EOK;
00219 }
00220
00237 int sockets_sendto_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages)
00238 {
00239 int value;
00240 int index;
00241 int message;
00242 int rc;
00243
00244 if (verbose)
00245 printf("\tSendto and recvfrom\t");
00246
00247 fflush(stdout);
00248
00249 for (index = 0; index < sockets; index++) {
00250 for (message = 0; message < messages; message++) {
00251 rc = sendto(socket_ids[index], data, size, 0, address, *addrlen);
00252 if (rc != EOK) {
00253 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
00254 socket_print_error(stderr, rc, "Socket send: ", "\n");
00255 return rc;
00256 }
00257 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
00258 if (value < 0) {
00259 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
00260 socket_print_error(stderr, value, "Socket receive: ", "\n");
00261 return value;
00262 }
00263 }
00264 if (verbose)
00265 print_mark(index);
00266 }
00267
00268 return EOK;
00269 }
00270
00277 void print_mark(int index)
00278 {
00279 if ((index + 1) % 10)
00280 printf("*");
00281 else
00282 printf("|");
00283 fflush(stdout);
00284 }
00285