UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
net.h
Go to the documentation of this file.
1 
5 /*
6 Copyright (C) 2002-2020 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23 */
24 
25 #pragma once
26 
27 class dbuffer;
28 struct net_stream;
29 struct datagram_socket;
30 struct sockaddr;
31 typedef void stream_onclose_func();
32 typedef void stream_callback_func(struct net_stream* s);
33 typedef void datagram_callback_func(struct datagram_socket* s, const char* buf, int len, struct sockaddr* from);
34 
35 bool SV_Start(const char* node, const char* service, stream_callback_func* func);
36 void SV_Stop(void);
37 
38 struct datagram_socket* NET_DatagramSocketNew(const char* node, const char* service, datagram_callback_func* datagram_func);
39 void NET_DatagramSend(struct datagram_socket* s, const char* buf, int len, struct sockaddr* to);
40 void NET_DatagramBroadcast(struct datagram_socket* s, const char* buf, int len, int port);
42 void NET_SockaddrToStrings(struct datagram_socket* s, struct sockaddr* addr, char* node, size_t nodelen, char* service, size_t servicelen);
43 bool NET_ResolvNode(const char* node, char* buf, size_t bufLength);
44 
45 void NET_Init(void);
46 void NET_Shutdown(void);
47 void NET_Wait(int timeout);
48 struct net_stream* NET_Connect(const char* node, const char* service, stream_onclose_func* onclose);
50 void NET_StreamEnqueue(struct net_stream* s, const char* data, int len);
51 int NET_StreamDequeue(struct net_stream* s, char* data, int len);
52 void* NET_StreamGetData(struct net_stream* s);
53 void NET_StreamSetData(struct net_stream* s, void* data);
54 const char* NET_StreamPeerToName(struct net_stream* s, char* dst, int len, bool appendPort);
55 const char* NET_StreamToString(struct net_stream* s);
56 bool NET_StreamIsLoopback(struct net_stream* s);
57 void NET_StreamFree(struct net_stream* s);
58 void NET_StreamFinished(struct net_stream* s);
60 
61 dbuffer* NET_ReadMsg(struct net_stream* s);
void SV_Stop(void)
Definition: net.cpp:1026
int NET_StreamDequeue(struct net_stream *s, char *data, int len)
Definition: net.cpp:760
bool NET_StreamIsLoopback(struct net_stream *s)
Definition: net.cpp:910
stream_callback_func * func
Definition: net.cpp:127
bool NET_ResolvNode(const char *node, char *buf, size_t bufLength)
Definition: net.cpp:1229
void NET_DatagramSocketClose(struct datagram_socket *s)
Definition: net.cpp:1182
stream_onclose_func * onclose
Definition: net.cpp:126
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.
Definition: net.cpp:644
void NET_Init(void)
Definition: net.cpp:305
void NET_StreamEnqueue(struct net_stream *s, const char *data, int len)
Enqueue a network message into a stream.
Definition: net.cpp:719
voidpf void * buf
Definition: ioapi.h:42
bool SV_Start(const char *node, const char *service, stream_callback_func *func)
Definition: net.cpp:990
void stream_callback_func(struct net_stream *s)
Definition: net.h:32
const char * NET_StreamToString(struct net_stream *s)
Returns the numerical representation of a net_stream.
Definition: net.cpp:859
void NET_SockaddrToStrings(struct datagram_socket *s, struct sockaddr *addr, char *node, size_t nodelen, char *service, size_t servicelen)
Convert sockaddr to string.
Definition: net.cpp:1212
void stream_onclose_func()
Definition: net.h:31
void NET_StreamFree(struct net_stream *s)
Call NET_StreamFree to dump the whole thing right now.
Definition: net.cpp:817
struct net_stream * NET_ConnectToLoopBack(stream_onclose_func *onclose)
Definition: net.cpp:681
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* ...
Definition: net.cpp:774
void datagram_callback_func(struct datagram_socket *s, const char *buf, int len, struct sockaddr *from)
Definition: net.h:33
void NET_StreamFinished(struct net_stream *s)
Call NET_StreamFinished to mark the stream as uninteresting, but to finish sending any data in the bu...
Definition: net.cpp:832
QGL_EXTERN GLuint GLchar GLuint * len
Definition: r_gl.h:99
void NET_Shutdown(void)
Definition: net.cpp:337
void * NET_StreamGetData(struct net_stream *s)
Definition: net.cpp:800
void NET_Wait(int timeout)
Definition: net.cpp:423
void NET_StreamSetData(struct net_stream *s, void *data)
Definition: net.cpp:805
void NET_DatagramSend(struct datagram_socket *s, const char *buf, int len, struct sockaddr *to)
Definition: net.cpp:1135
struct datagram_socket * NET_DatagramSocketNew(const char *node, const char *service, datagram_callback_func *datagram_func)
Opens a datagram socket (UDP)
Definition: net.cpp:1102
cvar_t * port
Definition: common.cpp:58
GLsizei const GLvoid * data
Definition: r_gl.h:152
const char * NET_StreamPeerToName(struct net_stream *s, char *dst, int len, bool appendPort)
Definition: net.cpp:872
void NET_DatagramBroadcast(struct datagram_socket *s, const char *buf, int len, int port)
Definition: net.cpp:1159
void NET_StreamSetCallback(struct net_stream *s, stream_callback_func *func)
Definition: net.cpp:903