Changeset 1a0fb3f8 in mainline


Ignore:
Timestamp:
2010-01-04T22:47:30Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ede63e4
Parents:
b648ae4
Message:

+ icmp and libsocket timeouting connecting

Location:
uspace/srv/net
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/net/app/ping/ping.c

    rb648ae4 r1a0fb3f8  
    236236        }
    237237
    238         icmp_phone = icmp_connect_module( SERVICE_ICMP );
     238        icmp_phone = icmp_connect_module( SERVICE_ICMP, ICMP_CONNECT_TIMEOUT );
    239239        if( icmp_phone < 0 ){
    240240                fprintf( stderr, "ICMP connect error %d\n", icmp_phone );
     241                return icmp_phone;
    241242        }
    242243
  • uspace/srv/net/include/icmp_common.h

    rb648ae4 r1a0fb3f8  
    4040#include <ipc/services.h>
    4141
     42#include <sys/time.h>
     43
     44/** Default timeout for incoming connections in microseconds.
     45 */
     46#define ICMP_CONNECT_TIMEOUT    ( 1 * 1000 * 1000 )
     47
    4248/** Connects to the ICMP module.
    4349 *  @param service The ICMP module service. Ignored parameter.
     50 *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
    4451 *  @returns The ICMP module phone on success.
    4552 *  @returns The ICMP socket identifier if called by the bundle module.
     53 *  @returns ETIMEOUT if the connection timeouted.
    4654 */
    47 int     icmp_connect_module( services_t service );
     55int     icmp_connect_module( services_t service, suseconds_t timeout );
    4856
    4957#endif
  • uspace/srv/net/include/socket.h

    rb648ae4 r1a0fb3f8  
    6262 *  @returns ENOMEM if there is not enough memory left.
    6363 *  @returns Other error codes as defined for the NET_SOCKET message.
     64 *  @returns Other error codes as defined for the bind_service_timeout() function.
    6465 */
    6566int     socket( int domain, int type, int protocol );
  • uspace/srv/net/modules.c

    rb648ae4 r1a0fb3f8  
    4141#include <ipc/services.h>
    4242
     43#include <sys/time.h>
     44
    4345#include "err.h"
    4446#include "modules.h"
    4547
    46 /** The time between connect requests.
     48/** The time between connect requests in microseconds.
    4749 */
    48 #define MODULE_WAIT_TIME        10000
     50#define MODULE_WAIT_TIME        ( 10 * 1000 )
    4951
    5052int connect_to_service( services_t need ){
     53        return connect_to_service_timeout( need, 0 );
     54}
     55
     56int connect_to_service_timeout( services_t need, suseconds_t timeout ){
    5157        int     phone;
    5258        int     res;
    5359
    54         //TODO timeout version?
    55         res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, ( ipcarg_t * ) & phone );
    56         while(( res < 0 ) || ( phone < 0 )){
     60        while( true ){
     61                res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, ( ipcarg_t * ) & phone );
     62                if(( res >= 0 ) && ( phone >= 0 )){
     63                        return phone;
     64                }
     65                if( timeout > 0 ){
     66                        timeout -= MODULE_WAIT_TIME;
     67                        if( timeout <= 0 ) return ETIMEOUT;
     68                }
    5769                usleep( MODULE_WAIT_TIME );
    58                 res = async_req_3_5( PHONE_NS, IPC_M_CONNECT_ME_TO, need, 0, 0, NULL, NULL, NULL, NULL, ( ipcarg_t * ) & phone );
    5970        }
    60         return phone;
    6171}
    6272
    6373int bind_service( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver ){
     74        return bind_service_timeout( need, arg1, arg2, arg3, client_receiver, 0 );
     75}
     76
     77int bind_service_timeout( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout ){
    6478        ERROR_DECLARE;
    6579
     
    6781        ipcarg_t        phonehash;
    6882
    69         phone = connect_to_service( need );
     83        phone = connect_to_service_timeout( need, timeout );
    7084        if( phone >= 0 ){
    7185                if( ERROR_OCCURRED( ipc_connect_to_me( phone, arg1, arg2, arg3, & phonehash ))){
  • uspace/srv/net/modules.h

    rb648ae4 r1a0fb3f8  
    4343#include <ipc/services.h>
    4444
     45#include <sys/time.h>
     46
    4547/** Converts the data length between different types.
    4648 *      @param[in] type_from The source type.
     
    6870int connect_to_service( services_t need );
    6971
     72/** Connects to the needed module.
     73 *  @param[in] need The needed module service.
     74 *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
     75 *  @returns The phone of the needed service.
     76 *  @returns ETIMEOUT if the connection timeouted.
     77 */
     78int connect_to_service_timeout( services_t need, suseconds_t timeout );
     79
    7080/** Creates bidirectional connection with the needed module service and registers the message receiver.
    7181 *  @param[in] need The needed module service.
     
    7888 */
    7989int     bind_service( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver );
     90
     91/** Creates bidirectional connection with the needed module service and registers the message receiver.
     92 *  @param[in] need The needed module service.
     93 *  @param[in] arg1 The first parameter.
     94 *  @param[in] arg2 The second parameter.
     95 *  @param[in] arg3 The third parameter.
     96 *  @param[in] client_receiver The message receiver.
     97 *  @param[in] timeout The connection timeout in microseconds. No timeout if set to zero (0).
     98 *  @returns The phone of the needed service.
     99 *  @returns ETIMEOUT if the connection timeouted.
     100 *  @returns Other error codes as defined for the ipc_connect_to_me() function.
     101 */
     102int     bind_service_timeout( services_t need, ipcarg_t arg1, ipcarg_t arg2, ipcarg_t arg3, async_client_conn_t client_receiver, suseconds_t timeout );
    80103
    81104/** Answers the call.
  • uspace/srv/net/socket/socket_client.c

    rb648ae4 r1a0fb3f8  
    7171#define SOCKET_MAX_ACCEPTED_SIZE                0
    7272
     73/** Default timeout for connections in microseconds.
     74 */
     75#define SOCKET_CONNECT_TIMEOUT  ( 1 * 1000 * 1000 )
     76
    7377/** Type definition of the socket specific data.
    7478 *  @see socket
     
    180184 *  Connects to the TCP module if necessary.
    181185 *  @returns The TCP module phone.
     186 *  @returns Other error codes as defined for the bind_service_timeout() function.
    182187 */
    183188static int      socket_get_tcp_phone( void );
     
    186191 *  Connects to the UDP module if necessary.
    187192 *  @returns The UDP module phone.
     193 *  @returns Other error codes as defined for the bind_service_timeout() function.
    188194 */
    189195static int      socket_get_udp_phone( void );
     
    262268static int socket_get_tcp_phone( void ){
    263269        if( socket_globals.tcp_phone < 0 ){
    264                 socket_globals.tcp_phone = bind_service( SERVICE_TCP, 0, 0, SERVICE_TCP, socket_connection );
     270                socket_globals.tcp_phone = bind_service_timeout( SERVICE_TCP, 0, 0, SERVICE_TCP, socket_connection, SOCKET_CONNECT_TIMEOUT );
    265271        }
    266272        return socket_globals.tcp_phone;
     
    269275static int socket_get_udp_phone( void ){
    270276        if( socket_globals.udp_phone < 0 ){
    271                 socket_globals.udp_phone = bind_service( SERVICE_UDP, 0, 0, SERVICE_UDP, socket_connection );
     277                socket_globals.udp_phone = bind_service_timeout( SERVICE_UDP, 0, 0, SERVICE_UDP, socket_connection, SOCKET_CONNECT_TIMEOUT );
    272278        }
    273279        return socket_globals.udp_phone;
     
    426432                        return EPFNOSUPPORT;
    427433        }
     434        if( phone < 0 ) return phone;
    428435        // create a new socket structure
    429436        socket = ( socket_ref ) malloc( sizeof( socket_t ));
  • uspace/srv/net/tl/icmp/icmp.c

    rb648ae4 r1a0fb3f8  
    4545#include <ipc/services.h>
    4646
     47#include <sys/time.h>
    4748#include <sys/types.h>
    4849
     
    508509}
    509510
    510 int icmp_connect_module( services_t service ){
     511int icmp_connect_module( services_t service, suseconds_t timeout ){
    511512        icmp_echo_ref   echo_data;
    512513        icmp_param_t    id;
  • uspace/srv/net/tl/icmp/icmp_common.c

    rb648ae4 r1a0fb3f8  
    4545#include "icmp_messages.h"
    4646
    47 int icmp_connect_module( services_t service ){
     47int icmp_connect_module( services_t service, suseconds_t timeout ){
    4848        int     phone;
    4949
    50         phone = connect_to_service( SERVICE_ICMP );
     50        phone = connect_to_service_timeout( SERVICE_ICMP, timeout );
    5151        if( phone >= 0 ){
    5252                async_req_0_0( phone, NET_ICMP_INIT );
  • uspace/srv/net/tl/tcp/tcp.c

    rb648ae4 r1a0fb3f8  
    219219        fibril_rwlock_initialize( & tcp_globals.lock );
    220220        fibril_rwlock_write_lock( & tcp_globals.lock );
    221         tcp_globals.icmp_phone = icmp_connect_module( SERVICE_ICMP );
    222         if( tcp_globals.icmp_phone < 0 ){
    223                 return tcp_globals.icmp_phone;
    224         }
     221        tcp_globals.icmp_phone = icmp_connect_module( SERVICE_ICMP, ICMP_CONNECT_TIMEOUT );
    225222        tcp_globals.ip_phone = ip_bind_service( SERVICE_IP, IPPROTO_TCP, SERVICE_TCP, client_connection, tcp_received_msg );
    226223        if( tcp_globals.ip_phone < 0 ){
  • uspace/srv/net/tl/udp/udp.c

    rb648ae4 r1a0fb3f8  
    198198        fibril_rwlock_initialize( & udp_globals.lock );
    199199        fibril_rwlock_write_lock( & udp_globals.lock );
    200         udp_globals.icmp_phone = icmp_connect_module( SERVICE_ICMP );
    201         if( udp_globals.icmp_phone < 0 ){
    202                 return udp_globals.icmp_phone;
    203         }
     200        udp_globals.icmp_phone = icmp_connect_module( SERVICE_ICMP, ICMP_CONNECT_TIMEOUT );
    204201        udp_globals.ip_phone = ip_bind_service( SERVICE_IP, IPPROTO_UDP, SERVICE_UDP, client_connection, udp_received_msg );
    205202        if( udp_globals.ip_phone < 0 ){
Note: See TracChangeset for help on using the changeset viewer.