VirtualBox

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

Last change on this file since 2935 was 932, checked in by vboxsync, 18 years ago

Added RTTcpServerDisconnectClient, this fixed the assertion mentioned in defect 1833.

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