VirtualBox

source: vbox/trunk/include/iprt/socket.h@ 27787

Last change on this file since 27787 was 27787, checked in by vboxsync, 15 years ago

iprt: RTSocket/RTTcp: refcount the sockets the RTDbg* way.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
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
43RT_C_DECLS_BEGIN
44
45/** @defgroup grp_rt_tcp RTSocket - Network Sockets
46 * @ingroup grp_rt
47 * @{
48 */
49
50/**
51 * Retains a reference to the socket handle.
52 *
53 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
54 *
55 * @param hSocket The socket handle.
56 */
57RTDECL(uint32_t) RTSocketRetain(RTSOCKET hSocket);
58
59/**
60 * Release a reference to the socket handle.
61 *
62 * When the reference count reaches zero, the socket handle is shut down and
63 * destroyed. This will not be graceful shutdown, use the protocol specific
64 * close method if this is desired.
65 *
66 * @returns New reference count, UINT32_MAX on invalid handle (asserted).
67 *
68 * @param hSocket The socket handle. The NIL handle is quietly
69 * ignored and 0 is returned.
70 */
71RTDECL(uint32_t) RTSocketRelease(RTSOCKET hSocket);
72
73/**
74 * Shuts down the socket, close it and then release one handle reference.
75 *
76 * This is slightly different from RTSocketRelease which will first do the
77 * shutting down and closing when the reference count reaches zero.
78 *
79 * @returns IPRT status code.
80 * @param hSocket The socket handle. NIL is ignored.
81 *
82 * @remarks This will not perform a graceful shutdown of the socket, it will
83 * just destroy it. Use the protocol specific close method if this is
84 * desired.
85 */
86RTDECL(int) RTSocketClose(RTSOCKET hSocket);
87
88/**
89 * Gets the native socket handle.
90 *
91 * @returns The native socket handle or RTHCUINTPTR_MAX if not invalid.
92 * @param hSocket The socket handle.
93 */
94RTDECL(RTHCUINTPTR) RTSocketToNative(RTSOCKET hSocket);
95
96/**
97 * Helper that ensures the correct inheritability of a socket.
98 *
99 * We're currently ignoring failures.
100 *
101 * @returns IPRT status code
102 * @param hSocket The socket handle.
103 * @param fInheritable The desired inheritability state.
104 */
105RTDECL(int) RTSocketSetInheritance(RTSOCKET hSocket, bool fInheritable);
106
107/**
108 * Receive data from a socket.
109 *
110 * @returns IPRT status code.
111 * @param hSocket The socket handle.
112 * @param pvBuffer Where to put the data we read.
113 * @param cbBuffer Read buffer size.
114 * @param pcbRead Number of bytes read. If NULL the entire buffer
115 * will be filled upon successful return. If not NULL a
116 * partial read can be done successfully.
117 */
118RTDECL(int) RTSocketRead(RTSOCKET hSocket, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
119
120/**
121 * Send data to a socket.
122 *
123 * @returns IPRT status code.
124 * @retval VERR_INTERRUPTED if interrupted before anything was written.
125 *
126 * @param hSocket The socket handle.
127 * @param pvBuffer Buffer to write data to socket.
128 * @param cbBuffer How much to write.
129 */
130RTDECL(int) RTSocketWrite(RTSOCKET hSocket, const void *pvBuffer, size_t cbBuffer);
131
132/**
133 * Checks if the socket is ready for reading (for I/O multiplexing).
134 *
135 * @returns IPRT status code.
136 * @param hSocket The socket handle.
137 * @param cMillies Number of milliseconds to wait for the socket. Use
138 * RT_INDEFINITE_WAIT to wait for ever.
139 */
140RTDECL(int) RTSocketSelectOne(RTSOCKET hSocket, RTMSINTERVAL cMillies);
141
142/**
143 * Shuts down one or both directions of communciation.
144 *
145 * @returns IPRT status code.
146 * @param hSocket The socket handle.
147 * @param fRead Whether to shutdown our read direction.
148 * @param fWrite Whether to shutdown our write direction.
149 */
150RTDECL(int) RTSocketShutdown(RTSOCKET hSocket, bool fRead, bool fWrite);
151
152/**
153 * Gets the address of the local side.
154 *
155 * @returns IPRT status code.
156 * @param Sock Socket descriptor.
157 * @param pAddr Where to store the local address on success.
158 */
159RTDECL(int) RTSocketGetLocalAddress(RTSOCKET hSocket, PRTNETADDR pAddr);
160
161/**
162 * Gets the address of the other party.
163 *
164 * @returns IPRT status code.
165 * @param Sock Socket descriptor.
166 * @param pAddr Where to store the peer address on success.
167 */
168RTDECL(int) RTSocketGetPeerAddress(RTSOCKET hSocket, PRTNETADDR pAddr);
169
170/** @} */
171RT_C_DECLS_END
172
173#endif
174
175
Note: See TracBrowser for help on using the repository browser.

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