VirtualBox

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

Last change on this file since 53087 was 50984, checked in by vboxsync, 11 years ago

crOpenGL: command blocks: enable in guest if host supports it; bugfixes

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