VirtualBox

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

Last change on this file since 1 was 1, checked in by vboxsync, 55 years ago

import

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