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 
47 
49 NetIOudp*
50 netioudp_new(gsize objsize
52  , PacketDecoder* decoder)
53 {
54  NetIO* iret;
55  NetIOudp* ret;
56  gint sockfd;
57 
58  if (objsize < sizeof(NetIOudp)) {
59  objsize = sizeof(NetIOudp);
60  }
61  iret = netio_new(objsize, config, decoder);
62  proj_class_register_subclassed(iret, "NetIOudp");
63  ret = CASTTOCLASS(NetIOudp, iret);
64  sockfd = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
65 #ifdef WIN32
66  {
67  u_long iMode=1;
68  ioctlsocket(sockfd, FIONBIO, &iMode);
69  }
70  ret->baseclass.giosock = g_io_channel_win32_new_socket(sockfd);
71 #else
72  ret->baseclass.giosock = g_io_channel_unix_new(sockfd);
73 #endif
74  g_io_channel_set_close_on_unref(ret->baseclass.giosock, TRUE);
75  return ret;
76 }
77 
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:50
Implements minimal client-oriented Frame and Frameset capabilities.
NetIOudp is a NetIO class subclass specialized to UDP connections.
Definition: netioudp.h:40
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:35
Defines interfaces a project Class system for class hierarchies in 'C'.
NetIO baseclass
Base class (NetIO) object.
Definition: netioudp.h:41
NetIO * netio_new(gsize objsize, ConfigContext *config, PacketDecoder *decoder)
NetIO constructor.
Definition: netio.c:360
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