NetBufferUtil.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #ifndef _WIN32
00022 #include <fcntl.h>
00023 #define SOCKET  int
00024 #else
00025 #include <winsock2.h>
00026 #endif
00027 
00028 #include <net/NetBufferUtil.h>
00029 
00030 // HACK HACK HACK
00031 // This code has been ripped from the SDL_net library
00032 // The library always sets the sockets to be non-blocking
00033 // this is NOT what we want as we use threads and do not
00034 // care.
00035 // This seems to be the only way to set blocking IO back on.
00036 
00037 struct _TCPsocket {
00038         int ready;
00039         SOCKET channel;
00040         IPaddress remoteAddress;
00041         IPaddress localAddress;
00042         int sflag;
00043 };
00044 
00045 void NetBufferUtil::setBlockingIO(TCPsocket &so)
00046 {
00047 #ifdef O_NONBLOCK
00048         /* Set the socket to blocking mode for accept() */
00049         fcntl(so->channel, F_SETFL, 0);
00050 #else
00051 #ifdef WIN32
00052         {
00053                 /* passing a zero value, socket mode set blocking */
00054                 unsigned long mode = 0;
00055                 ioctlsocket (so->channel, FIONBIO, &mode);
00056         }
00057 #else
00058 #warning How do we set blocking mode on other operating systems?
00059 #endif /* WIN32 */
00060 #endif /* O_NONBLOCK */
00061 }

Generated on Mon Feb 16 15:14:51 2009 for Scorched3D by  doxygen 1.5.3