source: mainline/uspace/app/nettest1/nettest.c@ c5b59ce

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c5b59ce was c5b59ce, checked in by Jakub Jermar <jakub@…>, 15 years ago

Integrate net_err.h into the standard library's err.h.

  • Property mode set to 100644
File size: 5.4 KB
RevLine 
[3be62bc]1/*
2 * Copyright (c) 2009 Lukas Mejdrech
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup nettest
30 * @{
31 */
32
33/** @file
34 * Networking test support functions implementation.
35 */
36
37#include <stdio.h>
[c5b59ce]38#include <err.h>
[3be62bc]39
[849ed54]40#include <socket.h>
[3be62bc]41
42#include "nettest.h"
43#include "print_error.h"
44
45int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
46 int index;
47
48 if(verbose){
49 printf("Create\t");
50 }
51 fflush(stdout);
52 for(index = 0; index < sockets; ++ index){
53 socket_ids[index] = socket(family, type, 0);
54 if(socket_ids[index] < 0){
55 printf("Socket %d (%d) error:\n", index, socket_ids[index]);
56 socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
57 return socket_ids[index];
58 }
59 if(verbose){
60 print_mark(index);
61 }
62 }
63 return EOK;
64}
65
66int sockets_close(int verbose, int * socket_ids, int sockets){
67 ERROR_DECLARE;
68
69 int index;
70
71 if(verbose){
72 printf("\tClose\t");
73 }
74 fflush(stdout);
75 for(index = 0; index < sockets; ++ index){
76 if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
77 printf("Socket %d (%d) error:\n", index, socket_ids[index]);
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
88int 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){
94 printf("\tConnect\t");
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
109int 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
112 int index;
113 int message;
114
115 if(verbose){
116 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))){
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
134int sockets_recvfrom(int verbose, int * socket_ids, int sockets, struct sockaddr * address, socklen_t * addrlen, char * data, int size, int messages){
135 int value;
136 int index;
137 int message;
138
139 if(verbose){
140 printf("\tRecvfrom\t");
141 }
142 fflush(stdout);
143 for(index = 0; index < sockets; ++ index){
144 for(message = 0; message < messages; ++ message){
145 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
146 if(value < 0){
147 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
148 socket_print_error(stderr, value, "Socket receive: ", "\n");
149 return value;
150 }
151 }
152 if(verbose){
153 print_mark(index);
154 }
155 }
156 return EOK;
157}
158
159int 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
162 int value;
163 int index;
164 int message;
165
166 if(verbose){
167 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))){
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;
176 }
177 value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
178 if(value < 0){
179 printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
180 socket_print_error(stderr, value, "Socket receive: ", "\n");
181 return value;
182 }
183 }
184 if(verbose){
185 print_mark(index);
186 }
187 }
188 return EOK;
189}
190
191void print_mark(int index){
192 if((index + 1) % 10){
193 printf("*");
194 }else{
195 printf("|");
196 }
197 fflush(stdout);
198}
199
200/** @}
201 */
Note: See TracBrowser for help on using the repository browser.