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 }