cr_net.h revision 0c0e78bbdcbeec81f856e8aa1097a9504c16bb1c
/* Copyright (c) 2001, Stanford University
* All rights reserved.
*
* See the file LICENSE.txt for information on redistributing this software.
*/
#ifndef CR_NET_H
#define CR_NET_H
#ifdef WINDOWS
#define WIN32_LEAN_AND_MEAN
#include <winsock.h>
#endif
#include <stdio.h>
#ifndef WINDOWS
#ifndef DARWIN
#ifdef AF_INET6
/* getaddrinfo & co appeared with ipv6 */
#define ADDRINFO
#endif
#endif
#endif
#ifdef SunOS
#endif
#include "cr_protocol.h"
#include "cr_threads.h"
#ifdef __cplusplus
extern "C" {
#endif
#define DEFAULT_SERVER_PORT 7000
/* If you change this, update DefaultMothershipPort in mothership.py */
#define DEFAULT_MOTHERSHIP_PORT 10000
typedef struct CRConnection CRConnection;
typedef enum {
#if defined(WINDOWS)
#else
typedef int CRSocket;
#endif
typedef void (*CRVoidFunc)( void );
typedef void (*CRNetCloseFunc)( unsigned int sender_id );
typedef struct __recvFuncList {
struct __recvFuncList *next;
typedef struct __closeFuncList {
struct __closeFuncList *next;
typedef struct __messageListNode {
unsigned int len; /* length of message (header + payload) */
typedef struct {
int numMessages;
/**
* Used to accumulate CR_MESSAGE_MULTI_BODY/TAIL chunks into one big buffer.
*/
typedef struct CRMultiBuffer {
unsigned int len; /* current length (<= max) (with sizeof_buffer_header) */
unsigned int max; /* size in bytes of data buffer */
void *buf; /* data buffer */
/**
* Chromium network connection (bidirectional).
*/
struct CRConnection {
int ignore;
unsigned int id; /* obtained from the mothership (if brokered) */
/* List of messages that we've received on the network connection but
* nobody has yet consumed.
*/
unsigned int mtu; /* max transmission unit size (in bytes) */
unsigned int buffer_size;
unsigned int krecv_buf_size;
int broker; /* is connection brokered through mothership? */
int threaded; /* is this a threaded connection? */
int endianness, swap;
int actual_network; /* is this a real network? */
unsigned char *userbuf;
int userbuf_len;
char *hostname;
int port;
/* To allocate a data buffer of size conn->buffer_size bytes */
/* To indicate the client's done with a data buffer */
/* To send a data buffer. If bufp is non-null, it must have been obtained
* from Alloc() and it'll be freed when Send() returns.
*/
/* To send a data buffer than can optionally be dropped on the floor */
/* To send 'len' bytes from buffer at 'start', no funny business */
/* To receive data. 'len' bytes will be placed into 'buf'. */
/* To receive one message on the connection */
/* What's this??? */
/* Called when a full CR_MESSAGE_MULTI_HEAD/TAIL message has been received */
/* To accept a new connection from a client */
/* To connect to a server (return 0 if error, 1 if success) */
/* To disconnect from a server */
unsigned int sizeof_buffer_header;
/* logging */
int total_bytes_sent;
int total_bytes_recv;
/* credits for flow control */
int send_credits;
int recv_credits;
int index;
#ifndef ADDRINFO
struct sockaddr_in remoteaddr;
#else
struct sockaddr_storage remoteaddr;
#endif
unsigned int seq;
unsigned int ack;
void *udp_packet;
int udp_packetlen;
/* FILE Tracing */
char *filename;
int fd;
/* Myrinet GM */
unsigned int gm_node_id;
unsigned int gm_port_num;
/* Mellanox IB */
unsigned int ib_node_id;
unsigned int ib_port_num;
/* Quadrics Elan3 (teac) */
int teac_id;
int teac_rank;
/* Quadrics Elan3 (tcscomm) */
int tcscomm_id;
int tcscomm_rank;
/* VBox HGCM */
#ifdef IN_GUEST
#endif
/* Used on host side to indicate that we are not allowed to store above pointers for later use
* in crVBoxHGCMReceiveMessage. As those messages are going to be processed after the correspoding
* HGCM call is finished and memory is freed. So we have to store a copy.
* This happens when message processing for client associated with this connection
* is blocked by another client, which has send us glBegin call and we're waiting to recieve glEnd.
*/
};
/*
* Network functions
*/
extern DECLEXPORT(void) crNetTearDown();
extern DECLEXPORT(void) crNetAccept( CRConnection *conn, const char *hostname, unsigned short port );
extern DECLEXPORT(void) crNetSend( CRConnection *conn, void **bufp, const void *start, unsigned int len );
extern DECLEXPORT(void) crNetBarf( CRConnection *conn, void **bufp, const void *start, unsigned int len );
extern DECLEXPORT(int) crNetRecv( void );
extern DECLEXPORT(void) crNetDispatchMessage( CRNetReceiveFuncList *rfl, CRConnection *conn, CRMessage *msg, unsigned int len );
extern DECLEXPORT(CRConnection *) crNetConnectToServer( const char *server, unsigned short default_port, int mtu, int broker );
extern DECLEXPORT(CRConnection *) crNetAcceptClient( const char *protocol, const char *hostname, unsigned short port, unsigned int mtu, int broker );
extern DECLEXPORT(void) crEnqueueMessage(CRMessageList *list, CRMessage *msg, unsigned int len, CRConnection *conn);
extern DECLEXPORT(void) crDequeueMessage(CRMessageList *list, CRMessage **msg, unsigned int *len, CRConnection **conn);
/*
* Quadrics stuff
*/
#define CR_QUADRICS_DEFAULT_LOW_CONTEXT 32
#define CR_QUADRICS_DEFAULT_HIGH_CONTEXT 35
/*
* Socket callback facility
*/
#define CR_SOCKET_CREATE 1
#define CR_SOCKET_DESTROY 2
#ifdef __cplusplus
}
#endif
#endif /* CR_NET_H */