VirtualBox

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

Last change on this file since 17108 was 15532, checked in by vboxsync, 16 years ago

crOpenGL: export to OSE

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