Changeset 7ae3d6f in mainline for uspace/app/nettest1/nettest.c


Ignore:
Timestamp:
2010-11-03T20:27:45Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f4057f5
Parents:
49d819b4 (diff), b445803 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/net.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nettest1/nettest.c

    r49d819b4 r7ae3d6f  
    2828
    2929/** @addtogroup nettest
    30  *  @{
     30 * @{
    3131 */
    3232
    3333/** @file
    34  *  Networking test support functions implementation.
     34 * Networking test support functions implementation.
    3535 */
    3636
     
    4343#include "print_error.h"
    4444
    45 int sockets_create(int verbose, int * socket_ids, int sockets, int family, sock_type_t type){
    46         int index;
    47 
    48         if(verbose){
     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 */
     56int sockets_create(int verbose, int *socket_ids, int sockets, int family, sock_type_t type)
     57{
     58        int index;
     59
     60        if (verbose)
    4961                printf("Create\t");
    50         }
    51         fflush(stdout);
    52         for(index = 0; index < sockets; ++ index){
     62               
     63        fflush(stdout);
     64       
     65        for (index = 0; index < sockets; index++) {
    5366                socket_ids[index] = socket(family, type, 0);
    54                 if(socket_ids[index] < 0){
     67                if (socket_ids[index] < 0) {
    5568                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
    5669                        socket_print_error(stderr, socket_ids[index], "Socket create: ", "\n");
    5770                        return socket_ids[index];
    5871                }
    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){
     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 */
     87int sockets_close(int verbose, int *socket_ids, int sockets)
     88{
     89        ERROR_DECLARE;
     90
     91        int index;
     92
     93        if (verbose)
    7294                printf("\tClose\t");
    73         }
    74         fflush(stdout);
    75         for(index = 0; index < sockets; ++ index){
    76                 if(ERROR_OCCURRED(closesocket(socket_ids[index]))){
     95
     96        fflush(stdout);
     97       
     98        for (index = 0; index < sockets; index++) {
     99                if (ERROR_OCCURRED(closesocket(socket_ids[index]))) {
    77100                        printf("Socket %d (%d) error:\n", index, socket_ids[index]);
    78101                        socket_print_error(stderr, ERROR_CODE, "Socket close: ", "\n");
    79102                        return ERROR_CODE;
    80103                }
    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){
     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 */
     121int 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)
    94128                printf("\tConnect\t");
    95         }
    96         fflush(stdout);
    97         for(index = 0; index < sockets; ++ index){
    98                 if(ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))){
     129       
     130        fflush(stdout);
     131       
     132        for (index = 0; index < sockets; index++) {
     133                if (ERROR_OCCURRED(connect(socket_ids[index], address, addrlen))) {
    99134                        socket_print_error(stderr, ERROR_CODE, "Socket connect: ", "\n");
    100135                        return ERROR_CODE;
    101136                }
    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){
     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 */
     157int sockets_sendto(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t addrlen, char *data, int size, int messages)
     158{
    110159        ERROR_DECLARE;
    111160
     
    113162        int message;
    114163
    115         if(verbose){
     164        if (verbose)
    116165                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))){
     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))) {
    122172                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    123173                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     
    125175                        }
    126176                }
    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){
     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 */
     197int sockets_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages)
     198{
    135199        int value;
    136200        int index;
    137201        int message;
    138202
    139         if(verbose){
     203        if (verbose)
    140204                printf("\tRecvfrom\t");
    141         }
    142         fflush(stdout);
    143         for(index = 0; index < sockets; ++ index){
    144                 for(message = 0; message < messages; ++ message){
     205       
     206        fflush(stdout);
     207       
     208        for (index = 0; index < sockets; index++) {
     209                for (message = 0; message < messages; message++) {
    145210                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
    146                         if(value < 0){
     211                        if (value < 0) {
    147212                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    148213                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     
    150215                        }
    151216                }
    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){
     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 */
     239int sockets_sendto_recvfrom(int verbose, int *socket_ids, int sockets, struct sockaddr *address, socklen_t *addrlen, char *data, int size, int messages)
     240{
    160241        ERROR_DECLARE;
    161242
     
    164245        int message;
    165246
    166         if(verbose){
     247        if (verbose)
    167248                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))){
     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))) {
    173255                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    174256                                socket_print_error(stderr, ERROR_CODE, "Socket send: ", "\n");
     
    176258                        }
    177259                        value = recvfrom(socket_ids[index], data, size, 0, address, addrlen);
    178                         if(value < 0){
     260                        if (value < 0) {
    179261                                printf("Socket %d (%d), message %d error:\n", index, socket_ids[index], message);
    180262                                socket_print_error(stderr, value, "Socket receive: ", "\n");
     
    182264                        }
    183265                }
    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){
     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 */
     279void print_mark(int index)
     280{
     281        if ((index + 1) % 10)
    193282                printf("*");
    194         }else{
     283        else
    195284                printf("|");
    196         }
    197285        fflush(stdout);
    198286}
Note: See TracChangeset for help on using the changeset viewer.