VirtualBox

source: vbox/trunk/include/iprt/tcp.h@ 26588

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

iprt: New type RTNETADDR for storing any address + type + port. Added %RTnaddr for printing it.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.9 KB
Line 
1/** @file
2 * IPRT - TCP/IP.
3 */
4
5/*
6 * Copyright (C) 2006-2007 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_tcp_h
31#define ___iprt_tcp_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 RTFile APIs available Ring-0 Host Context!"
40#endif
41
42
43RT_C_DECLS_BEGIN
44
45/** @defgroup grp_rt_tcp RTTcp - TCP/IP
46 * @ingroup grp_rt
47 * @{
48 */
49
50
51/**
52 * Serve a TCP Server connection.
53 *
54 * @returns iprt status code.
55 * @returns VERR_TCP_SERVER_STOP to terminate the server loop forcing
56 * the RTTcpCreateServer() call to return.
57 * @param Sock The socket which the client is connected to.
58 * The call will close this socket.
59 * @param pvUser User argument.
60 */
61typedef DECLCALLBACK(int) FNRTTCPSERVE(RTSOCKET Sock, void *pvUser);
62/** Pointer to a RTTCPSERVE(). */
63typedef FNRTTCPSERVE *PFNRTTCPSERVE;
64
65/** Pointer to a RTTCPSERVER handle. */
66typedef struct RTTCPSERVER *PRTTCPSERVER;
67/** Pointer to a RTTCPSERVER handle. */
68typedef PRTTCPSERVER *PPRTTCPSERVER;
69
70/**
71 * Create single connection at a time TCP Server in a separate thread.
72 *
73 * The thread will loop accepting connections and call pfnServe for
74 * each of the incoming connections in turn. The pfnServe function can
75 * return VERR_TCP_SERVER_STOP too terminate this loop. RTTcpServerDestroy()
76 * should be used to terminate the server.
77 *
78 * @returns iprt status code.
79 * @param pszAddress The address for creating a listening socket.
80 * If NULL or empty string the server is bound to all interfaces.
81 * @param uPort The port for creating a listening socket.
82 * @param enmType The thread type.
83 * @param pszThrdName The name of the worker thread.
84 * @param pfnServe The function which will serve a new client connection.
85 * @param pvUser User argument passed to pfnServe.
86 * @param ppServer Where to store the serverhandle.
87 */
88RTR3DECL(int) RTTcpServerCreate(const char *pszAddress, unsigned uPort, RTTHREADTYPE enmType, const char *pszThrdName,
89 PFNRTTCPSERVE pfnServe, void *pvUser, PPRTTCPSERVER ppServer);
90
91/**
92 * Create single connection at a time TCP Server.
93 * The caller must call RTTcpServerListen() to actually start the server.
94 *
95 * @returns iprt status code.
96 * @param pszAddress The address for creating a listening socket.
97 * If NULL the server is bound to all interfaces.
98 * @param uPort The port for creating a listening socket.
99 * @param ppServer Where to store the serverhandle.
100 */
101RTR3DECL(int) RTTcpServerCreateEx(const char *pszAddress, uint32_t uPort, PPRTTCPSERVER ppServer);
102
103/**
104 * Closes down and frees a TCP Server.
105 * This will also terminate any open connections to the server.
106 *
107 * @returns iprt status code.
108 * @param pServer Handle to the server.
109 */
110RTR3DECL(int) RTTcpServerDestroy(PRTTCPSERVER pServer);
111
112/**
113 * Listen for incoming connections.
114 *
115 * The function will loop accepting connections and call pfnServe for
116 * each of the incoming connections in turn. The pfnServe function can
117 * return VERR_TCP_SERVER_STOP too terminate this loop. A stopped server
118 * can only be destroyed.
119 *
120 * @returns iprt status code.
121 * @param pServer The server handle as returned from RTTcpServerCreateEx().
122 * @param pfnServe The function which will serve a new client connection.
123 * @param pvUser User argument passed to pfnServe.
124 */
125RTR3DECL(int) RTTcpServerListen(PRTTCPSERVER pServer, PFNRTTCPSERVE pfnServe, void *pvUser);
126
127/**
128 * Terminate the open connection to the server.
129 *
130 * @returns iprt status code.
131 * @param pServer Handle to the server.
132 */
133RTR3DECL(int) RTTcpServerDisconnectClient(PRTTCPSERVER pServer);
134
135/**
136 * Shuts down the server, leaving client connections open.
137 *
138 * @returns IPRT status code.
139 * @param pServer Handle to the server.
140 */
141RTR3DECL(int) RTTcpServerShutdown(PRTTCPSERVER pServer);
142
143/**
144 * Connect (as a client) to a TCP Server.
145 *
146 * @returns iprt status code.
147 * @param pszAddress The address to connect to.
148 * @param uPort The port to connect to.
149 * @param pSock Where to store the handle to the established connection.
150 */
151RTR3DECL(int) RTTcpClientConnect(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock);
152
153/**
154 * Close a socket returned by RTTcpClientConnect().
155 *
156 * @returns iprt status code.
157 * @param Sock Socket descriptor.
158 */
159RTR3DECL(int) RTTcpClientClose(RTSOCKET Sock);
160
161/**
162 * Receive data from a socket.
163 *
164 * @returns iprt status code.
165 * @param Sock Socket descriptor.
166 * @param pvBuffer Where to put the data we read.
167 * @param cbBuffer Read buffer size.
168 * @param pcbRead Number of bytes read.
169 * If NULL the entire buffer will be filled upon successful return.
170 * If not NULL a partial read can be done successfully.
171 */
172RTR3DECL(int) RTTcpRead(RTSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead);
173
174/**
175 * Send data from a socket.
176 *
177 * @returns iprt status code.
178 * @param Sock Socket descriptor.
179 * @param pvBuffer Buffer to write data to socket.
180 * @param cbBuffer How much to write.
181 */
182RTR3DECL(int) RTTcpWrite(RTSOCKET Sock, const void *pvBuffer, size_t cbBuffer);
183
184/**
185 * Flush socket write buffers.
186 *
187 * @returns iprt status code.
188 * @param Sock Socket descriptor.
189 */
190RTR3DECL(int) RTTcpFlush(RTSOCKET Sock);
191
192/**
193 * Socket I/O multiplexing.
194 * Checks if the socket is ready for reading.
195 *
196 * @returns iprt status code.
197 * @param Sock Socket descriptor.
198 * @param cMillies Number of milliseconds to wait for the socket.
199 * Use RT_INDEFINITE_WAIT to wait for ever.
200 */
201RTR3DECL(int) RTTcpSelectOne(RTSOCKET Sock, RTMSINTERVAL cMillies);
202
203
204#if 0 /* skipping these for now - RTTcpServer* handles this. */
205/**
206 * Listen for connection on a socket.
207 *
208 * @returns iprt status code.
209 * @param Sock Socket descriptor.
210 * @param cBackLog The maximum length the queue of pending connections
211 * may grow to.
212 */
213RTR3DECL(int) RTTcpListen(RTSOCKET Sock, int cBackLog);
214
215/**
216 * Accept a connection on a socket.
217 *
218 * @returns iprt status code.
219 * @param Sock Socket descriptor.
220 * @param uPort The port for accepting connection.
221 * @param pSockAccepted Where to store the handle to the accepted connection.
222 */
223RTR3DECL(int) RTTcpAccept(RTSOCKET Sock, unsigned uPort, PRTSOCKET pSockAccepted);
224
225#endif
226
227/**
228 * Gets the address of the other party.
229 *
230 * @returns IPRT status code.
231 * @param Sock Socket descriptor.
232 * @param pAddr Where to store the peer address on success.
233 */
234RTR3DECL(int) RTTcpGetPeerAddress(RTSOCKET Sock, PRTNETADDR pAddr);
235
236/** @} */
237RT_C_DECLS_END
238
239#endif
240
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