1 | /** @file
|
---|
2 | * IPRT - Network Sockets.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2010 Sun Microsystems, Inc.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
9 | * available from http://www.virtualbox.org. This file is free software;
|
---|
10 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
11 | * General Public License (GPL) as published by the Free Software
|
---|
12 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
13 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
14 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
15 | *
|
---|
16 | * The contents of this file may alternatively be used under the terms
|
---|
17 | * of the Common Development and Distribution License Version 1.0
|
---|
18 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
19 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
20 | * CDDL are applicable instead of those of the GPL.
|
---|
21 | *
|
---|
22 | * You may elect to license modified versions of this file under the
|
---|
23 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
24 | *
|
---|
25 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
26 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
27 | * additional information or have any questions.
|
---|
28 | */
|
---|
29 |
|
---|
30 | #ifndef ___iprt_socket_h
|
---|
31 | #define ___iprt_socket_h
|
---|
32 |
|
---|
33 | #include <iprt/cdefs.h>
|
---|
34 | #include <iprt/types.h>
|
---|
35 | #include <iprt/thread.h>
|
---|
36 | #include <iprt/net.h>
|
---|
37 |
|
---|
38 | #ifdef IN_RING0
|
---|
39 | # error "There are no RTSocket APIs available Ring-0 Host Context!"
|
---|
40 | #endif
|
---|
41 |
|
---|
42 |
|
---|
43 | RT_C_DECLS_BEGIN
|
---|
44 |
|
---|
45 | /** @defgroup grp_rt_tcp RTSocket - Network Sockets
|
---|
46 | * @ingroup grp_rt
|
---|
47 | * @{
|
---|
48 | */
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Destroys the specified handle, freeing associated resources and closing the
|
---|
52 | * socket.
|
---|
53 | *
|
---|
54 | * @returns IPRT status code.
|
---|
55 | * @param hSocket The socket handle. NIL is ignored.
|
---|
56 | *
|
---|
57 | * @remarks This will not perform a graceful shutdown of the socket, it will
|
---|
58 | * just destroy it. Use the protocol specific close method if this is
|
---|
59 | * desired.
|
---|
60 | */
|
---|
61 | RTDECL(int) RTSocketDestroy(RTSOCKET hSocket);
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Gets the native socket handle.
|
---|
65 | *
|
---|
66 | * @returns The native socket handle or RTHCUINTPTR_MAX if not invalid.
|
---|
67 | * @param hSocket The socket handle.
|
---|
68 | */
|
---|
69 | RTDECL(RTHCUINTPTR) RTSocketToNative(RTSOCKET hSocket);
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Helper that ensures the correct inheritability of a socket.
|
---|
73 | *
|
---|
74 | * We're currently ignoring failures.
|
---|
75 | *
|
---|
76 | * @returns IPRT status code
|
---|
77 | * @param hSocket The socket handle.
|
---|
78 | * @param fInheritable The desired inheritability state.
|
---|
79 | */
|
---|
80 | RTDECL(int) RTSocketSetInheritance(RTSOCKET hSocket, bool fInheritable);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Receive data from a socket.
|
---|
84 | *
|
---|
85 | * @returns IPRT status code.
|
---|
86 | * @param hSocket The socket handle.
|
---|
87 | * @param pvBuffer Where to put the data we read.
|
---|
88 | * @param cbBuffer Read buffer size.
|
---|
89 | * @param pcbRead Number of bytes read. If NULL the entire buffer
|
---|
90 | * will be filled upon successful return. If not NULL a
|
---|
91 | * partial read can be done successfully.
|
---|
92 | */
|
---|
93 | RTDECL(int) RTSocketRead(RTSOCKET hSocket, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Send data to a socket.
|
---|
97 | *
|
---|
98 | * @returns IPRT status code.
|
---|
99 | * @retval VERR_INTERRUPTED if interrupted before anything was written.
|
---|
100 | *
|
---|
101 | * @param hSocket The socket handle.
|
---|
102 | * @param pvBuffer Buffer to write data to socket.
|
---|
103 | * @param cbBuffer How much to write.
|
---|
104 | */
|
---|
105 | RTDECL(int) RTSocketWrite(RTSOCKET hSocket, const void *pvBuffer, size_t cbBuffer);
|
---|
106 |
|
---|
107 | /**
|
---|
108 | * Checks if the socket is ready for reading (for I/O multiplexing).
|
---|
109 | *
|
---|
110 | * @returns IPRT status code.
|
---|
111 | * @param hSocket The socket handle.
|
---|
112 | * @param cMillies Number of milliseconds to wait for the socket. Use
|
---|
113 | * RT_INDEFINITE_WAIT to wait for ever.
|
---|
114 | */
|
---|
115 | RTDECL(int) RTSocketSelectOne(RTSOCKET hSocket, RTMSINTERVAL cMillies);
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Shuts down one or both directions of communciation.
|
---|
119 | *
|
---|
120 | * @returns IPRT status code.
|
---|
121 | * @param hSocket The socket handle.
|
---|
122 | * @param fRead Whether to shutdown our read direction.
|
---|
123 | * @param fWrite Whether to shutdown our write direction.
|
---|
124 | */
|
---|
125 | RTDECL(int) RTSocketShutdown(RTSOCKET hSocket, bool fRead, bool fWrite);
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * Gets the address of the local side.
|
---|
129 | *
|
---|
130 | * @returns IPRT status code.
|
---|
131 | * @param Sock Socket descriptor.
|
---|
132 | * @param pAddr Where to store the local address on success.
|
---|
133 | */
|
---|
134 | RTDECL(int) RTSocketGetLocalAddress(RTSOCKET hSocket, PRTNETADDR pAddr);
|
---|
135 |
|
---|
136 | /**
|
---|
137 | * Gets the address of the other party.
|
---|
138 | *
|
---|
139 | * @returns IPRT status code.
|
---|
140 | * @param Sock Socket descriptor.
|
---|
141 | * @param pAddr Where to store the peer address on success.
|
---|
142 | */
|
---|
143 | RTDECL(int) RTSocketGetPeerAddress(RTSOCKET hSocket, PRTNETADDR pAddr);
|
---|
144 |
|
---|
145 | /** @} */
|
---|
146 | RT_C_DECLS_END
|
---|
147 |
|
---|
148 | #endif
|
---|
149 |
|
---|
150 |
|
---|