VirtualBox

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

Last change on this file since 7170 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

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