comparison src/g23m-fad/tcpip/rnet/rnet_rt/rnet_rt_api_connect.c @ 1:d393cd9bb723

src/g23m-*: initial import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 15 Jul 2018 04:40:46 +0000
parents
children
comparison
equal deleted inserted replaced
0:b6a5e36de839 1:d393cd9bb723
1 /**
2 * @file rnet_rt_api_connect.c
3 *
4 * RNET_RT API
5 *
6 * @author Regis Feneon
7 * @version 0.1
8 */
9
10 /*
11 * $Id: rnet_rt_api_connect.c,v 1.3 2002/10/30 15:23:34 rf Exp $
12 * $Name: ti_20021030 $
13 *
14 * History:
15 *
16 * Date Author Modification
17 * --------------------------------------------------
18 * 3/22/2002 Regis Feneon Create
19 *
20 * (C) Copyright 2002 by TI, All Rights Reserved
21 *
22 */
23
24 #include "rnet_cfg.h"
25 #ifdef RNET_CFG_REAL_TRANSPORT
26
27 #include "rnet_rt_i.h"
28 #include "rnet_rt_env.h"
29
30 #include "rnet_trace_i.h"
31
32 /**
33 * Sets up the connection ID to connect to the remote host.
34 *
35 * For the connection-oriented client (TCP), it prepares a connection from the local
36 * to the peer system. The connection oriented client does not need
37 * to call rnet_bind() before rnet_connect(), since rnet_connect() would automatically
38 * use the local address of the client and allocate dynamically a free local port.
39 *
40 * rnet_connect() returns immediately, does not wait for the connection to be properly setup.
41 * The RNET_CONNECT_CFM message is sent when the connection is established.
42 * If the connection could not be properly established, a RNET_ERROR_IND
43 * message is sent.
44 *
45 * A connectionless client (UDP) would use rnet_connect() to locally specify
46 * the remote server, but no connection is open. But the remote address
47 * is then known and does not need to be specified again.
48 * rnet_connect() takes as parameter a fully initialized address structure,
49 * specifying server address and port.
50 *
51 * @param desc Connection identifier [IN].
52 * @param peer_addr Peer address [IN].
53 * @param peer_port Peer port [IN].
54 * @return RNET_MEMORY_ERR No buffer space available.
55 * RNET_NOT_INITIALIZED NET subsystem not initialized (internal error).
56 * RNET_INTERNAL_ERR Network subsystem failed.
57 * or Attempt to connect forcefully rejected.
58 * or Attempt to connect datagram socket to broadcast address
59 * RNET_INVALID_PARAMETER Invalid connection ID.
60 * or Remote address not a valid address (such as ADDR_ANY).
61 * RNET_NOT_SUPPORTED Addresses in the specified family cannot be used with this socket.
62 * RNET_IN_USE Already connected (connection-oriented only).
63 * RNET_NET_UNREACHABLE The network cannot be reached from this host at this time.
64 * RNET_TIMEOUT Attempt to connect timed out without establishing a connection.
65 * RNET_NOT_READY Still processing a callback function.
66 * RNET_OK Connection in progress
67 * RNET_CONNECT_CFM will be sent when the connection
68 * has been successfully completed.
69 */
70
71 T_RNET_RET rnet_rt_connect (T_RNET_DESC * desc,
72 T_RNET_IP_ADDR peer_addr,
73 T_RNET_PORT peer_port)
74 {
75 NGsockaddr addr;
76 int err;
77
78 addr.sin_port = ngHTONS( peer_port);
79 addr.sin_addr = ngHTONL( peer_addr);
80
81 /* connect to peer */
82 rvf_lock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
83 err = ngSAIOConnect( (NGsock *) desc, &addr, 0);
84
85 if( err == NG_EINPROGRESS) {
86
87 /* send msg when connection completed */
88 ((T_RNET_RT_SOCK *) desc)->flags |= RNET_RT_SOCKF_NOTIFY_CONNECT;
89 err = NG_EOK;
90 }
91
92 rvf_unlock_mutex( &rnet_rt_env_ctrl_blk_p->mutex);
93
94 return( rnet_rt_ngip_error( err));
95 }
96
97 #endif /* ifdef RNET_CFG_REAL_TRANSPORT */
98