[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Win32 Sockets



The following minor changes to %net.c will allow sockets to work on
the MSVC version of Goo v146:

Change the include section to be:

#include <stdio.h>
#include <stdlib.h>
#if !defined(_MSC_VER)
#include <unistd.h>
#include <netdb.h>
#else
#include <winsock.h>
#endif
#include <fcntl.h>
#include <errno.h>
#if !defined(_MSC_VER)
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif


Add:

#if defined(_MSC_VER)
int win32_start_sockets()
{
  static int sockets_started = 0;

  if(!sockets_started)
  {
    WSADATA data;
	if(WSAStartup(MAKEWORD(1, 1), &data) != 0)
	{
      return 0;
    }

    
    sockets_started = 1;
   
  }
  return 1;
}

#endif

Change:

GOOFUNC(new_socket) ()
{
  int sock;
 
#if defined(_MSC_VER)
  if(!win32_start_sockets())
  {
    return YPfalse;
  }
#endif

  sock = socket(AF_INET, SOCK_STREAM, 0); // default protocol.

  if (sock < 0)
    return YPfalse;

  return sockWrap(sock);
}

Change:

GOOFUNC(make_non_blocking) (P sockfd)
{
  int opts;
  int sock = sockUnwrap(sockfd);
#if defined(_MSC_VER)
  return YPfalse;
#else
  opts = fcntl(sock, F_GETFL);
  if(opts < 0)
    {
      return YPfalse;
    }

  opts |= O_NONBLOCK;

  if(fcntl(sock, F_SETFL, opts) < 0)
    {
      return YPfalse;
    }

  return YPtrue;
#endif
}

Chris.
-- 
http://radio.weblogs.com/0102385