The Assimilation Project
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
netioudp.c
Go to the documentation of this file.
1 
24 #include <memory.h>
25 #include <sys/types.h>
26 #ifdef _MSC_VER
27 # include <winsock2.h>
28 #else
29 # include <unistd.h>
30 # include <sys/socket.h>
31 # include <netinet/in.h>
32 #endif
33 #include <address_family_numbers.h>
34 #include <proj_classes.h>
35 #include <netioudp.h>
36 #include <frameset.h>
37 
38 
46 
48 NetIOudp*
49 netioudp_new(gsize objsize
51  , PacketDecoder* decoder)
52 {
53  NetIO* iret;
54  NetIOudp* ret;
55  gint sockfd;
56 
57  if (objsize < sizeof(NetIOudp)) {
58  objsize = sizeof(NetIOudp);
59  }
60  iret = netio_new(objsize, config, decoder);
61  proj_class_register_subclassed(iret, "NetIOudp");
62  ret = CASTTOCLASS(NetIOudp, iret);
63  sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
64 #ifdef WIN32
65  {
66  u_long iMode=1;
67  ioctlsocket(sockfd, FIONBIO, &iMode);
68  }
69  ret->baseclass.giosock = g_io_channel_win32_new_socket(sockfd);
70 #else
71  ret->baseclass.giosock = g_io_channel_unix_new(sockfd);
72 #endif
73  g_io_channel_set_close_on_unref(ret->baseclass.giosock, TRUE);
74  return ret;
75 }
IETF/IANA Address family assignments.
Implements UDP network I/O (NetIOudp) class.
NetIOudp * netioudp_new(gsize objsize, ConfigContext *config, PacketDecoder *decoder)
Construct new UDP NetIO object (and its socket, etc)
Definition: netioudp.c:49
Implements minimal client-oriented Frame and Frameset capabilities.
NetIOudp is a NetIO class subclass specialized to UDP connections.
Definition: netioudp.h:39
gpointer proj_class_register_subclassed(gpointer object, const char *static_subclassname)
Log the creation of a subclassed object from a superclassed object.
Definition: proj_classes.c:192
struct _NetIOudp NetIOudp
Definition: netioudp.h:34
Defines interfaces a project Class system for class hierarchies in 'C'.
NetIO baseclass
Base class (NetIO) object.
Definition: netioudp.h:40
NetIO * netio_new(gsize objsize, ConfigContext *config, PacketDecoder *decoder)
NetIO constructor.
Definition: netio.c:368
GIOChannel * giosock
Glib GIOChannel for this socket.
Definition: netio.h:61
#define CASTTOCLASS(Cclass, obj)
Safely cast 'obj' to C-class 'class' - verifying that it was registerd as being of type class ...
Definition: proj_classes.h:66
This is a basic NetIO class abstract class for doing network I/O.
Definition: netio.h:58