VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_net.h@ 42499

Last change on this file since 42499 was 42499, checked in by vboxsync, 12 years ago

crOgl/wddm: per-context connections

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 10.8 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved.
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#ifndef CR_NET_H
8#define CR_NET_H
9
10#ifdef WINDOWS
11#define WIN32_LEAN_AND_MEAN
12#pragma warning( push, 3 ) /* shut up about warnings in YOUR OWN HEADER FILES!!! */
13#include <winsock.h>
14#endif
15
16#include <stdio.h>
17
18#ifndef WINDOWS
19#include <sys/socket.h>
20#ifndef DARWIN
21#ifdef AF_INET6
22/* getaddrinfo & co appeared with ipv6 */
23#define ADDRINFO
24#endif
25#endif
26#include <netinet/in.h>
27#endif
28
29#ifdef SunOS
30#include <sys/types.h>
31#endif
32
33#include "cr_protocol.h"
34#include "cr_threads.h"
35
36#include <iprt/types.h>
37#include <iprt/thread.h>
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
43#define DEFAULT_SERVER_PORT 7000
44
45/* If you change this, update DefaultMothershipPort in mothership.py */
46#define DEFAULT_MOTHERSHIP_PORT 10000
47
48typedef struct CRConnection CRConnection;
49
50typedef enum {
51 CR_NO_CONNECTION,
52 CR_SDP,
53 CR_TCPIP,
54 CR_UDPTCPIP,
55 CR_FILE,
56 CR_GM,
57 CR_IB,
58 CR_TEAC,
59 CR_TCSCOMM,
60 CR_VBOXHGCM,
61 CR_DROP_PACKETS
62} CRConnectionType;
63
64#if defined(WINDOWS)
65typedef SOCKET CRSocket;
66#else
67typedef int CRSocket;
68#endif
69
70typedef void (*CRVoidFunc)( void );
71typedef int (*CRNetReceiveFunc)( CRConnection *conn, CRMessage *msg, unsigned int len );
72typedef int (*CRNetConnectFunc)( CRConnection *conn );
73typedef void (*CRNetCloseFunc)( unsigned int sender_id );
74
75typedef struct __recvFuncList {
76 CRNetReceiveFunc recv;
77 struct __recvFuncList *next;
78} CRNetReceiveFuncList;
79
80typedef struct __closeFuncList {
81 CRNetCloseFunc close;
82 struct __closeFuncList *next;
83} CRNetCloseFuncList;
84
85typedef struct __messageListNode {
86 CRMessage *mesg; /* the actual message (header + payload) */
87 unsigned int len; /* length of message (header + payload) */
88 CRConnection *conn; /* some messages are assoc. with specific connections*/
89 struct __messageListNode *next; /* next in list */
90} CRMessageListNode;
91
92typedef struct {
93 CRMessageListNode *head, *tail;
94 int numMessages;
95 CRmutex lock;
96 CRcondition nonEmpty;
97} CRMessageList;
98
99
100/**
101 * Used to accumulate CR_MESSAGE_MULTI_BODY/TAIL chunks into one big buffer.
102 */
103typedef struct CRMultiBuffer {
104 unsigned int len; /* current length (<= max) (with sizeof_buffer_header) */
105 unsigned int max; /* size in bytes of data buffer */
106 void *buf; /* data buffer */
107} CRMultiBuffer;
108
109#ifdef VBOX_WITH_CRHGSMI
110# ifdef IN_GUEST
111typedef struct CRVBOXHGSMI_CLIENT {
112 struct VBOXUHGSMI *pHgsmi;
113 struct VBOXUHGSMI_BUFFER *pCmdBuffer;
114 struct VBOXUHGSMI_BUFFER *pHGBuffer;
115 void *pvHGBuffer;
116 struct CRBufferPool_t *bufpool;
117} CRVBOXHGSMI_CLIENT, *PCRVBOXHGSMI_CLIENT;
118#endif /* IN_GUEST */
119#endif /* #ifdef VBOX_WITH_CRHGSMI */
120/**
121 * Chromium network connection (bidirectional).
122 */
123struct CRConnection {
124 int ignore;
125 CRConnectionType type;
126 unsigned int id; /* obtained from the mothership (if brokered) */
127
128 /* List of messages that we've received on the network connection but
129 * nobody has yet consumed.
130 */
131 CRMessageList messageList;
132
133 CRMultiBuffer multi;
134
135 unsigned int mtu; /* max transmission unit size (in bytes) */
136 unsigned int buffer_size;
137 unsigned int krecv_buf_size;
138 int broker; /* is connection brokered through mothership? */
139 int threaded; /* is this a threaded connection? */
140 int endianness, swap;
141 int actual_network; /* is this a real network? */
142
143 unsigned char *userbuf;
144 int userbuf_len;
145
146 char *hostname;
147 int port;
148
149 /* To allocate a data buffer of size conn->buffer_size bytes */
150 void *(*Alloc)( CRConnection *conn );
151 /* To indicate the client's done with a data buffer */
152 void (*Free)( CRConnection *conn, void *buf );
153 /* To send a data buffer. If bufp is non-null, it must have been obtained
154 * from Alloc() and it'll be freed when Send() returns.
155 */
156 void (*Send)( CRConnection *conn, void **buf, const void *start, unsigned int len );
157 /* To send a data buffer than can optionally be dropped on the floor */
158 void (*Barf)( CRConnection *conn, void **buf, const void *start, unsigned int len );
159 /* To send 'len' bytes from buffer at 'start', no funny business */
160 void (*SendExact)( CRConnection *conn, const void *start, unsigned int len );
161 /* To receive data. 'len' bytes will be placed into 'buf'. */
162 void (*Recv)( CRConnection *conn, void *buf, unsigned int len );
163 /* To receive one message on the connection */
164 void (*RecvMsg)( CRConnection *conn );
165 /* What's this??? */
166 void (*InstantReclaim)( CRConnection *conn, CRMessage *mess );
167 /* Called when a full CR_MESSAGE_MULTI_HEAD/TAIL message has been received */
168 void (*HandleNewMessage)( CRConnection *conn, CRMessage *mess, unsigned int len );
169 /* To accept a new connection from a client */
170 void (*Accept)( CRConnection *conn, const char *hostname, unsigned short port );
171 /* To connect to a server (return 0 if error, 1 if success) */
172 int (*Connect)( CRConnection *conn );
173 /* To disconnect from a server */
174 void (*Disconnect)( CRConnection *conn );
175
176 unsigned int sizeof_buffer_header;
177
178 /* logging */
179 int total_bytes_sent;
180 int total_bytes_recv;
181 int recv_count;
182 int opcodes_count;
183
184 /* credits for flow control */
185 int send_credits;
186 int recv_credits;
187
188 /* TCP/IP */
189 CRSocket tcp_socket;
190 int index;
191
192 CRSocket sdp_socket;
193
194 /* UDP/IP */
195 CRSocket udp_socket;
196#ifndef ADDRINFO
197 struct sockaddr_in remoteaddr;
198#else
199 struct sockaddr_storage remoteaddr;
200#endif
201
202 /* UDP/TCP/IP */
203 unsigned int seq;
204 unsigned int ack;
205 void *udp_packet;
206 int udp_packetlen;
207
208 /* FILE Tracing */
209 enum { CR_FILE_WRITE, CR_FILE_READ } file_direction;
210 char *filename;
211 int fd;
212
213 /* Myrinet GM */
214 unsigned int gm_node_id;
215 unsigned int gm_port_num;
216
217 /* Mellanox IB */
218 unsigned int ib_node_id;
219 unsigned int ib_port_num;
220
221 /* Quadrics Elan3 (teac) */
222 int teac_id;
223 int teac_rank;
224
225 /* Quadrics Elan3 (tcscomm) */
226 int tcscomm_id;
227 int tcscomm_rank;
228
229 /* VBox HGCM */
230 uint32_t u32ClientID;
231 uint8_t *pBuffer;
232 uint32_t cbBuffer;
233 uint8_t *pHostBuffer;
234 uint32_t cbHostBufferAllocated;
235 uint32_t cbHostBuffer;
236#ifdef IN_GUEST
237 uint32_t u32InjectClientID;
238# ifdef VBOX_WITH_CRHGSMI
239 CRVBOXHGSMI_CLIENT HgsmiClient;
240 struct VBOXUHGSMI *pExternalHgsmi;
241# endif
242#else
243# ifdef VBOX_WITH_CRHGSMI
244 struct _crclient *pClient; /* back reference, just for simplicity */
245 CRVBOXHGSMI_CMDDATA CmdData;
246# endif
247#endif
248 /* Used on host side to indicate that we are not allowed to store above pointers for later use
249 * in crVBoxHGCMReceiveMessage. As those messages are going to be processed after the corresponding
250 * HGCM call is finished and memory is freed. So we have to store a copy.
251 * This happens when message processing for client associated with this connection
252 * is blocked by another client, which has send us glBegin call and we're waiting to receive glEnd.
253 */
254 uint8_t allow_redir_ptr;
255
256 uint32_t vMajor, vMinor; /*Protocol version*/
257};
258
259
260/*
261 * Network functions
262 */
263extern DECLEXPORT(int) crGetHostname( char *buf, unsigned int len );
264
265extern DECLEXPORT(void) crNetInit( CRNetReceiveFunc recvFunc, CRNetCloseFunc closeFunc );
266extern DECLEXPORT(void) crNetTearDown();
267
268extern DECLEXPORT(void) *crNetAlloc( CRConnection *conn );
269extern DECLEXPORT(void) crNetFree( CRConnection *conn, void *buf );
270
271extern DECLEXPORT(void) crNetAccept( CRConnection *conn, const char *hostname, unsigned short port );
272extern DECLEXPORT(int) crNetConnect( CRConnection *conn );
273extern DECLEXPORT(void) crNetDisconnect( CRConnection *conn );
274extern DECLEXPORT(void) crNetFreeConnection( CRConnection *conn );
275extern DECLEXPORT(void) crCloseSocket( CRSocket sock );
276
277extern DECLEXPORT(void) crNetSend( CRConnection *conn, void **bufp, const void *start, unsigned int len );
278extern DECLEXPORT(void) crNetBarf( CRConnection *conn, void **bufp, const void *start, unsigned int len );
279extern DECLEXPORT(void) crNetSendExact( CRConnection *conn, const void *start, unsigned int len );
280extern DECLEXPORT(void) crNetSingleRecv( CRConnection *conn, void *buf, unsigned int len );
281extern DECLEXPORT(unsigned int) crNetGetMessage( CRConnection *conn, CRMessage **message );
282extern DECLEXPORT(unsigned int) crNetPeekMessage( CRConnection *conn, CRMessage **message );
283extern DECLEXPORT(int) crNetNumMessages(CRConnection *conn);
284extern DECLEXPORT(void) crNetReadline( CRConnection *conn, void *buf );
285extern DECLEXPORT(int) crNetRecv(
286#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
287 CRConnection *conn
288#endif
289 );
290#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
291#define CR_WRITEBACK_WAIT(_conn, _writeback) do { \
292 while (_writeback) { \
293 RTThreadYield(); \
294 crNetRecv(_conn); \
295 } \
296 } while (0)
297#else
298#define CR_WRITEBACK_WAIT(_conn, _writeback) do { \
299 while (_writeback) { \
300 RTThreadYield(); \
301 crNetRecv(); \
302 } \
303 } while (0)
304
305#endif
306extern DECLEXPORT(void) crNetDefaultRecv( CRConnection *conn, CRMessage *msg, unsigned int len );
307extern DECLEXPORT(void) crNetDispatchMessage( CRNetReceiveFuncList *rfl, CRConnection *conn, CRMessage *msg, unsigned int len );
308
309extern DECLEXPORT(CRConnection *) crNetConnectToServer( const char *server, unsigned short default_port, int mtu, int broker
310#if defined(VBOX_WITH_CRHGSMI) && defined(IN_GUEST)
311 , struct VBOXUHGSMI *pHgsmi
312#endif
313);
314extern DECLEXPORT(CRConnection *) crNetAcceptClient( const char *protocol, const char *hostname, unsigned short port, unsigned int mtu, int broker );
315
316
317extern DECLEXPORT(void) crInitMessageList(CRMessageList *list);
318extern DECLEXPORT(void) crEnqueueMessage(CRMessageList *list, CRMessage *msg, unsigned int len, CRConnection *conn);
319extern DECLEXPORT(void) crDequeueMessage(CRMessageList *list, CRMessage **msg, unsigned int *len, CRConnection **conn);
320
321extern DECLEXPORT(void) crNetRecvReadPixels( const CRMessageReadPixels *rp, unsigned int len );
322
323
324/*
325 * Quadrics stuff
326 */
327#define CR_QUADRICS_DEFAULT_LOW_CONTEXT 32
328#define CR_QUADRICS_DEFAULT_HIGH_CONTEXT 35
329
330extern DECLEXPORT(void) crNetSetRank( int my_rank );
331extern DECLEXPORT(void) crNetSetContextRange( int low_context, int high_context );
332extern DECLEXPORT(void) crNetSetNodeRange( const char *low_node, const char *high_node );
333extern DECLEXPORT(void) crNetSetKey( const unsigned char* key, const int keyLength );
334
335
336/*
337 * Socket callback facility
338 */
339#define CR_SOCKET_CREATE 1
340#define CR_SOCKET_DESTROY 2
341typedef void (*CRSocketCallbackProc)(int mode, int socket);
342extern DECLEXPORT(void) crRegisterSocketCallback(int mode, CRSocketCallbackProc proc);
343
344
345#ifdef __cplusplus
346}
347#endif
348
349#endif /* CR_NET_H */
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