GuestHost/installation/VBoxWinDrvInst.cpp: Try harder if DiInstallDriverW() returns...
[vbox.git] / include / iprt / udp.h
blob5dc80bc3184a94d142dc680a0d4f1d517f5ed7fe
1 /** @file
2 * IPRT - UDP/IP.
3 */
5 /*
6 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
36 #ifndef IPRT_INCLUDED_udp_h
37 #define IPRT_INCLUDED_udp_h
38 #ifndef RT_WITHOUT_PRAGMA_ONCE
39 # pragma once
40 #endif
42 #include <iprt/cdefs.h>
43 #include <iprt/types.h>
44 #include <iprt/thread.h>
45 #include <iprt/net.h>
46 #include <iprt/sg.h>
47 #include <iprt/socket.h>
49 #ifdef IN_RING0
50 # error "There are no RTFile APIs available Ring-0 Host Context!"
51 #endif
54 RT_C_DECLS_BEGIN
56 /** @defgroup grp_rt_udp RTUdp - UDP/IP
57 * @ingroup grp_rt
58 * @{
62 /**
63 * Handle incoming UDP datagrams.
65 * @returns iprt status code.
66 * @returns VERR_UDP_SERVER_STOP to terminate the server loop forcing
67 * the RTUdpCreateServer() call to return.
68 * @param Sock The socket on which the datagram needs to be received.
69 * @param pvUser User argument.
71 typedef DECLCALLBACKTYPE(int, FNRTUDPSERVE,(RTSOCKET Sock, void *pvUser));
72 /** Pointer to a RTUDPSERVE(). */
73 typedef FNRTUDPSERVE *PFNRTUDPSERVE;
75 /**
76 * Create single datagram at a time UDP Server in a separate thread.
78 * The thread will loop accepting datagrams and call pfnServe for
79 * each of the incoming datagrams in turn. The pfnServe function can
80 * return VERR_UDP_SERVER_STOP too terminate this loop. RTUdpServerDestroy()
81 * should be used to terminate the server.
83 * @returns iprt status code.
84 * @param pszAddress The address for creating a datagram socket.
85 * If NULL or empty string the server is bound to all interfaces.
86 * @param uPort The port for creating a datagram socket.
87 * @param enmType The thread type.
88 * @param pszThrdName The name of the worker thread.
89 * @param pfnServe The function which will handle incoming datagrams.
90 * @param pvUser User argument passed to pfnServe.
91 * @param ppServer Where to store the serverhandle.
93 RTR3DECL(int) RTUdpServerCreate(const char *pszAddress, unsigned uPort, RTTHREADTYPE enmType, const char *pszThrdName,
94 PFNRTUDPSERVE pfnServe, void *pvUser, PPRTUDPSERVER ppServer);
96 /**
97 * Create single datagram at a time UDP Server.
98 * The caller must call RTUdpServerReceive() to actually start the server.
100 * @returns iprt status code.
101 * @param pszAddress The address for creating a datagram socket.
102 * If NULL the server is bound to all interfaces.
103 * @param uPort The port for creating a datagram socket.
104 * @param ppServer Where to store the serverhandle.
106 RTR3DECL(int) RTUdpServerCreateEx(const char *pszAddress, uint32_t uPort, PPRTUDPSERVER ppServer);
109 * Shuts down the server.
111 * @returns IPRT status code.
112 * @param pServer Handle to the server.
114 RTR3DECL(int) RTUdpServerShutdown(PRTUDPSERVER pServer);
117 * Closes down and frees a UDP Server.
119 * @returns iprt status code.
120 * @param pServer Handle to the server.
122 RTR3DECL(int) RTUdpServerDestroy(PRTUDPSERVER pServer);
125 * Listen for incoming datagrams.
127 * The function will loop waiting for datagrams and call pfnServe for
128 * each of the incoming datagrams in turn. The pfnServe function can
129 * return VERR_UDP_SERVER_STOP too terminate this loop. A stopped server
130 * can only be destroyed.
132 * @returns iprt status code.
133 * @param pServer The server handle as returned from RTUdpServerCreateEx().
134 * @param pfnServe The function which will handle incoming datagrams.
135 * @param pvUser User argument passed to pfnServe.
137 RTR3DECL(int) RTUdpServerListen(PRTUDPSERVER pServer, PFNRTUDPSERVE pfnServe, void *pvUser);
140 * Receive data from a socket.
142 * @returns iprt status code.
143 * @param Sock Socket descriptor.
144 * @param pvBuffer Where to put the data we read.
145 * @param cbBuffer Read buffer size.
146 * @param pcbRead Number of bytes read. Must be non-NULL.
147 * @param pSrcAddr The network address to read from.
149 RTR3DECL(int) RTUdpRead(RTSOCKET Sock, void *pvBuffer, size_t cbBuffer, size_t *pcbRead, PRTNETADDR pSrcAddr);
152 * Send data to a socket.
154 * @returns iprt status code.
155 * @retval VERR_INTERRUPTED if interrupted before anything was written.
157 * @param pServer Handle to the server.
158 * @param pvBuffer Buffer to write data to socket.
159 * @param cbBuffer How much to write.
160 * @param pDstAddr Destination address.
162 RTR3DECL(int) RTUdpWrite(PRTUDPSERVER pServer, const void *pvBuffer,
163 size_t cbBuffer, PCRTNETADDR pDstAddr);
166 * Create and connect a data socket.
168 * @returns iprt status code.
169 * @param pszAddress The address to connect to.
170 * @param uPort The port to connect to.
171 * @param pLocalAddr The local address to bind this socket to, can be
172 * NULL.
173 * @param pSock Where to store the handle to the established connection.
175 RTR3DECL(int) RTUdpCreateClientSocket(const char *pszAddress, uint32_t uPort, PRTNETADDR pLocalAddr, PRTSOCKET pSock);
178 * Create a data socket acting as a server.
180 * @returns iprt status code.
181 * @param pszAddress The address to connect to.
182 * @param uPort The port to connect to.
183 * @param pSock Where to store the handle to the established connection.
185 RTR3DECL(int) RTUdpCreateServerSocket(const char *pszAddress, uint32_t uPort, PRTSOCKET pSock);
187 /** @} */
188 RT_C_DECLS_END
190 #endif /* !IPRT_INCLUDED_udp_h */