VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/socket.h@ 16303

Last change on this file since 16303 was 16291, checked in by vboxsync, 16 years ago

NAT: multi threading.
Introduces set of macroces to use locking/unlocking/creating/destroing mutexes
Also every socket enqueueing is accomponement with lock creation
(it doen't work yet, compilable on Windows don't know about Linux)

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1/*
2 * Copyright (c) 1995 Danny Gasparovski.
3 *
4 * Please read the file COPYRIGHT for the
5 * terms and conditions of the copyright.
6 */
7
8/* MINE */
9
10#ifndef _SLIRP_SOCKET_H_
11#define _SLIRP_SOCKET_H_
12#ifdef VBOX_WITH_SLIRP_MT
13#include <iprt/semaphore.h>
14#endif
15
16#define SO_EXPIRE 240000
17#define SO_EXPIREFAST 10000
18
19/*
20 * Our socket structure
21 */
22
23struct socket
24{
25 struct socket *so_next;
26 struct socket *so_prev; /* For a linked list of sockets */
27
28#if !defined(RT_OS_WINDOWS)
29 int s; /* The actual socket */
30#else
31 union {
32 int s;
33 HANDLE sh;
34 };
35 uint64_t so_icmp_id; /* XXX: hack */
36 uint64_t so_icmp_seq; /* XXX: hack */
37#endif
38
39 /* XXX union these with not-yet-used sbuf params */
40 struct mbuf *so_m; /* Pointer to the original SYN packet,
41 * for non-blocking connect()'s, and
42 * PING reply's */
43 struct tcpiphdr *so_ti; /* Pointer to the original ti within
44 * so_mconn, for non-blocking connections */
45 int so_urgc;
46 struct in_addr so_faddr; /* foreign host table entry */
47 struct in_addr so_laddr; /* local host table entry */
48 u_int16_t so_fport; /* foreign port */
49 u_int16_t so_lport; /* local port */
50 u_int16_t so_hlport; /* host local port */
51 struct in_addr so_hladdr; /* local host addr */
52
53 u_int8_t so_iptos; /* Type of service */
54 u_int8_t so_emu; /* Is the socket emulated? */
55
56 u_char so_type; /* Type of socket, UDP or TCP */
57 int so_state; /* internal state flags SS_*, below */
58
59 struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */
60 u_int so_expire; /* When the socket will expire */
61
62 int so_queued; /* Number of packets queued from this socket */
63 int so_nqueued; /* Number of packets queued in a row
64 * Used to determine when to "downgrade" a session
65 * from fastq to batchq */
66
67 struct sbuf so_rcv; /* Receive buffer */
68 struct sbuf so_snd; /* Send buffer */
69#ifdef VBOX_WITH_SLIRP_MT
70 RTSEMMUTEX so_mutex;
71#endif
72};
73
74#ifdef VBOX_WITH_SLIRP_MT
75# define SOCKET_LOCK(so) \
76 do { \
77 int rc = RTSemMutexRequest((so)->so_mutex, RT_INDEFINITE_WAIT); \
78 AssertReleaseRC(rc); \
79 } while (0)
80# define SOCKET_UNLOCK(so) \
81 do { \
82 int rc = RTSemMutexRelease((so)->so_mutex); \
83 AssertReleaseRC(rc); \
84 } while (0)
85# define SOCKET_LOCK_CREATE(so) \
86 do { \
87 int rc = RTSemMutexCreate(&(so)->so_mutex); \
88 AssertReleaseRC(rc); \
89 } while (0)
90# define SOCKET_LOCK_DESTROY(so) \
91 do { \
92 int rc = RTSemMutexDestroy((so)->so_mutex); \
93 AssertReleaseRC(rc); \
94 } while (0)
95#else
96# define SOCKET_LOCK(so) do {} while (0)
97# define SOCKET_UNLOCK(so) do {} while (0)
98# define SOCKET_LOCK_CREATE(so) do {} while (0)
99# define SOCKET_LOCK_DESTROY(so) do {} while (0)
100#endif
101/*
102 * Socket state bits. (peer means the host on the Internet,
103 * local host means the host on the other end of the modem)
104 */
105#define SS_NOFDREF 0x001 /* No fd reference */
106
107#define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
108#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
109#define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
110#define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
111/* #define SS_ISFDISCONNECTED 0x020*/ /* Socket has disconnected from peer, in 2MSL state */
112#define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
113
114/* #define SS_CTL 0x080 */
115#define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
116#define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
117
118extern struct socket tcb;
119
120#if defined(DECLARE_IOVEC) && !defined(HAVE_READV)
121struct iovec
122{
123 char *iov_base;
124 size_t iov_len;
125};
126#endif
127
128void so_init _P((void));
129struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int));
130struct socket * socreate _P((void));
131void sofree _P((PNATState, struct socket *));
132int soread _P((PNATState, struct socket *, int));
133void sorecvoob _P((PNATState, struct socket *));
134int sosendoob _P((struct socket *));
135int sowrite _P((PNATState, struct socket *));
136void sorecvfrom _P((PNATState, struct socket *));
137int sosendto _P((PNATState, struct socket *, struct mbuf *));
138struct socket * solisten _P((PNATState, u_int, u_int32_t, u_int, int));
139void sorwakeup _P((struct socket *));
140void sowwakeup _P((struct socket *));
141void soisfconnecting _P((register struct socket *));
142void soisfconnected _P((register struct socket *));
143void sofcantrcvmore _P((struct socket *));
144void sofcantsendmore _P((struct socket *));
145void soisfdisconnected _P((struct socket *));
146void sofwdrain _P((struct socket *));
147
148#endif /* _SOCKET_H_ */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette