UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
net.h File Reference

Go to the source code of this file.

Typedefs

typedef void stream_onclose_func ()
 
typedef void stream_callback_func (struct net_stream *s)
 
typedef void datagram_callback_func (struct datagram_socket *s, const char *buf, int len, struct sockaddr *from)
 

Functions

bool SV_Start (const char *node, const char *service, stream_callback_func *func)
 
void SV_Stop (void)
 
struct datagram_socketNET_DatagramSocketNew (const char *node, const char *service, datagram_callback_func *datagram_func)
 Opens a datagram socket (UDP) More...
 
void NET_DatagramSend (struct datagram_socket *s, const char *buf, int len, struct sockaddr *to)
 
void NET_DatagramBroadcast (struct datagram_socket *s, const char *buf, int len, int port)
 
void NET_DatagramSocketClose (struct datagram_socket *s)
 
void NET_SockaddrToStrings (struct datagram_socket *s, struct sockaddr *addr, char *node, size_t nodelen, char *service, size_t servicelen)
 Convert sockaddr to string. More...
 
bool NET_ResolvNode (const char *node, char *buf, size_t bufLength)
 
void NET_Init (void)
 
void NET_Shutdown (void)
 
void NET_Wait (int timeout)
 
struct net_streamNET_Connect (const char *node, const char *service, stream_onclose_func *onclose)
 Try to connect to a given host on a given port. More...
 
struct net_streamNET_ConnectToLoopBack (stream_onclose_func *onclose)
 
void NET_StreamEnqueue (struct net_stream *s, const char *data, int len)
 Enqueue a network message into a stream. More...
 
int NET_StreamDequeue (struct net_stream *s, char *data, int len)
 
voidNET_StreamGetData (struct net_stream *s)
 
void NET_StreamSetData (struct net_stream *s, void *data)
 
const char * NET_StreamPeerToName (struct net_stream *s, char *dst, int len, bool appendPort)
 
const char * NET_StreamToString (struct net_stream *s)
 Returns the numerical representation of a net_stream. More...
 
bool NET_StreamIsLoopback (struct net_stream *s)
 
void NET_StreamFree (struct net_stream *s)
 Call NET_StreamFree to dump the whole thing right now. More...
 
void NET_StreamFinished (struct net_stream *s)
 Call NET_StreamFinished to mark the stream as uninteresting, but to finish sending any data in the buffer. The stream will appear closed after this call, and at some unspecified point in the future s will become an invalid pointer, so it should not be further referenced. More...
 
void NET_StreamSetCallback (struct net_stream *s, stream_callback_func *func)
 
dbufferNET_ReadMsg (struct net_stream *s)
 Reads messages from the network channel and adds them to the dbuffer where you can use the NET_Read* functions to get the values in the correct order. More...
 

Typedef Documentation

typedef void datagram_callback_func(struct datagram_socket *s, const char *buf, int len, struct sockaddr *from)

Definition at line 33 of file net.h.

typedef void stream_callback_func(struct net_stream *s)

Definition at line 32 of file net.h.

typedef void stream_onclose_func()

Definition at line 31 of file net.h.

Function Documentation

struct net_stream* NET_Connect ( const char *  node,
const char *  service,
stream_onclose_func onclose 
)

Try to connect to a given host on a given port.

Parameters
[in]nodeThe host to connect to
[in]serviceThe port to connect to
[in]oncloseThe callback that is called on closing the returned stream. This is useful if you hold the pointer for the returned stream anywhere else and would like to get notified once this pointer is invalid.
See also
NET_DoConnect
NET_ConnectToLoopBack
Todo:
What about a timeout

Definition at line 644 of file net.cpp.

References AI_ADDRCONFIG, AI_NUMERICSERV, Com_Printf(), index, cvar_s::integer, NET_DoConnect(), NET_StreamGetFree(), and OBJZERO.

Referenced by CL_Connect(), GAME_GetImportData(), and Irc_Net_Connect().

struct net_stream* NET_ConnectToLoopBack ( stream_onclose_func onclose)
Parameters
[in]oncloseThe callback that is called on closing the returned stream. This is useful if you hold the pointer for the returned stream anywhere else and would like to get notified once this pointer is invalid.
See also
NET_Connect

Definition at line 681 of file net.cpp.

References Com_Printf(), net_stream::func, net_stream::inbound, net_stream::loopback, net_stream::loopback_peer, NET_StreamGetFree(), NET_StreamNew(), net_stream::onclose, net_stream::outbound, server_func, and server_running.

Referenced by CL_Connect().

void NET_DatagramBroadcast ( struct datagram_socket s,
const char *  buf,
int  len,
int  port 
)
See also
NET_DatagramSend
NET_DatagramSocketNew
Todo:
This is only sending on the first available device, what if we have several devices?

Definition at line 1159 of file net.cpp.

References Com_Error(), ERR_DROP, datagram_socket::family, and NET_DatagramSend().

Referenced by GAME_GetImportData().

struct datagram_socket* NET_DatagramSocketNew ( const char *  node,
const char *  service,
datagram_callback_func func 
)

Opens a datagram socket (UDP)

See also
NET_DatagramSocketDoNew
Parameters
[in]nodeThe numeric address to resolv (might be nullptr)
[in]serviceThe port number
[in]funcCallback function for data handling

Definition at line 1102 of file net.cpp.

References AI_ADDRCONFIG, AI_NUMERICSERV, Com_Printf(), datagram_socket::func, cvar_s::integer, NET_DatagramSocketDoNew(), and OBJZERO.

Referenced by GAME_GetImportData(), and SV_InitGame().

dbuffer* NET_ReadMsg ( struct net_stream s)

Reads messages from the network channel and adds them to the dbuffer where you can use the NET_Read* functions to get the values in the correct order.

See also
NET_StreamDequeue

Definition at line 774 of file net.cpp.

References dbuffer::add(), len, LittleLong, NET_StreamDequeue(), NET_StreamGetLength(), NET_StreamPeek(), netMutex, and v.

Referenced by CL_ReadPackets(), GAME_GetImportData(), and SV_ReadPacket().

bool NET_ResolvNode ( const char *  node,
char *  buf,
size_t  bufLength 
)

Definition at line 1229 of file net.cpp.

References NET_AddrinfoToString(), and NET_GetAddrinfoForNode().

Referenced by HTTP_ResolvURL(), and TEST_F().

void NET_SockaddrToStrings ( struct datagram_socket s,
struct sockaddr *  addr,
char *  node,
size_t  nodelen,
char *  service,
size_t  servicelen 
)

Convert sockaddr to string.

Parameters
[in]sThe datagram socket type to get the addrlen from
[in]addrThe socket address to convert into a string
[out]nodeThe target node name buffer
[in]nodelenThe length of the node name buffer
[out]serviceThe target service name buffer
[in]servicelenThe length of the service name buffer

Definition at line 1212 of file net.cpp.

References datagram_socket::addrlen, Com_Printf(), and Q_strncpyz().

Referenced by GAME_GetImportData().

int NET_StreamDequeue ( struct net_stream s,
char *  data,
int  len 
)
See also
NET_StreamEnqueue

Definition at line 760 of file net.cpp.

References dbuffer::extract(), net_stream::finished, and net_stream::inbound.

Referenced by Irc_Proto_PollServerMsg(), and NET_ReadMsg().

void NET_StreamEnqueue ( struct net_stream s,
const char *  data,
int  len 
)
void NET_StreamFinished ( struct net_stream s)

Call NET_StreamFinished to mark the stream as uninteresting, but to finish sending any data in the buffer. The stream will appear closed after this call, and at some unspecified point in the future s will become an invalid pointer, so it should not be further referenced.

Definition at line 832 of file net.cpp.

References dbuffer_len, net_stream::finished, net_stream::inbound, INVALID_SOCKET, net_stream::loopback_peer, NET_StreamClose(), netMutex, net_stream::outbound, read_fds, and net_stream::socket.

Referenced by CL_Disconnect(), SV_DropClient(), and SV_FinalMessage().

void NET_StreamFree ( struct net_stream s)

Call NET_StreamFree to dump the whole thing right now.

See also
NET_StreamClose
NET_StreamFinished

Definition at line 817 of file net.cpp.

References net_stream::finished, and NET_StreamClose().

Referenced by GAME_GetImportData(), Irc_Net_Connect(), Irc_Net_Disconnect(), NET_StreamNew(), and SV_ReadPacket().

void* NET_StreamGetData ( struct net_stream s)

Definition at line 800 of file net.cpp.

References net_stream::data.

Referenced by GAME_GetImportData(), and SV_ReadPacket().

bool NET_StreamIsLoopback ( struct net_stream s)

Definition at line 910 of file net.cpp.

References net_stream::loopback.

Referenced by CL_ConnectionlessPacket(), and NET_StreamPeerToName().

const char* NET_StreamPeerToName ( struct net_stream s,
char *  dst,
int  len,
bool  appendPort 
)
Parameters
[in]sThe network stream to get the name for
[out]dstThe target buffer to store the ip and port in
[in]lenThe length of the target buffer
[in]appendPortAlso append the port number to the target buffer

Definition at line 872 of file net.cpp.

References net_stream::addrlen, Com_Printf(), Com_sprintf(), NET_StreamIsLoopback(), Q_strncpyz(), and net_stream::socket.

Referenced by GAME_GetImportData(), NET_ShowStreams_f(), NET_StreamToString(), NET_Wait(), SV_ConnectionlessPacket(), SV_Status_f(), SVC_BucketForAddress(), SVC_DirectConnect(), and SVC_RemoteCommand().

void NET_StreamSetCallback ( struct net_stream s,
stream_callback_func func 
)

Definition at line 903 of file net.cpp.

References net_stream::func.

Referenced by GAME_GetImportData().

void NET_StreamSetData ( struct net_stream s,
void data 
)

Definition at line 805 of file net.cpp.

References net_stream::data.

Referenced by GAME_GetImportData(), and SVC_DirectConnect().

const char* NET_StreamToString ( struct net_stream s)

Returns the numerical representation of a net_stream.

Note
Not thread safe!

Definition at line 859 of file net.cpp.

References NET_StreamPeerToName().

Referenced by SVC_Info(), SVC_Status(), and SVC_TeamInfo().

bool SV_Start ( const char *  node,
const char *  service,
stream_callback_func func 
)
See also
NET_DoStartServer
Parameters
[in]nodeThe node to start the server with
[in]serviceIf this is nullptr we are in single player mode
[in]funcThe server callback function to read the packets
See also
SV_ReadPacket
server_func
SV_Stop

Definition at line 990 of file net.cpp.

References Com_Printf(), INVALID_SOCKET, NET_DoStartServer(), NET_GetAddrinfoForNode(), server_func, server_running, and server_socket.

Referenced by SV_InitGame().

void SV_Stop ( void  )
See also
SV_Start

Definition at line 1026 of file net.cpp.

References INVALID_SOCKET, netCloseSocket, read_fds, server_func, server_running, and server_socket.

Referenced by SV_Shutdown().