bug-gnubg
[Top][All Lists]
Advanced

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

Re: Bug-gnubg] Winsock (Was: [Bug-gnubg] Multiprocessing)


From: Nardy Pillards
Subject: Re: Bug-gnubg] Winsock (Was: [Bug-gnubg] Multiprocessing)
Date: Wed, 9 Jul 2003 23:12:28 +0200

From: "Olivier Baur" <address@hidden>
Sent: Wednesday, July 09, 2003 2:47 PM

> > Example of sockets and Win32
> > (from http://web.presby.edu/~wasmith/courses/315/samples/sockets/ )
> >
> > #include <iostream>
> > #include <string>
> > #include <fstream>
> > #ifdef WIN32
> > #include <windows.h>     // this includes winsock2 (among many other 
> > things)
> > #include <io.h>          // needed for read, write
> > #else
> > #include <sys/socket.h> // basic socket definitions
> > #include <netinet/in.h> // sockaddr_in and other Internet defns
> > #include <arpa/inet.h> // inet(3) functions
> > #include <unistd.h> // needed for read, write
> > #include <strings.h> // for bzero
> > #include <stdlib.h>     // for atoi
> > #endif
> 
> You should modify the #include's as explained above.

that's done:
#ifdef WIN32
#include <winsock2.h>
#include <io.h>
#else

> 
> The following should be added somewhere in gnubg.c: real_main() I think
> 
> real_main()
> {
> /* declarations */
> > #ifdef WIN32
> >   WSADATA              wsaData;
> >   int                  Ret;
> > #endif
> 
> /* instructions */
> > #ifdef WIN32
> >   if ((Ret = WSAStartup(MAKEWORD(2,2), &wsaData)) != 0) {
> >     cerr << "winsock startup error" << endl;
> >     return -1;
> >   }
> > #endif
> 
> /* real_main() main loop here */
> 
> > #ifdef WIN32
> >     WSACleanup();
> > #endif
> 
> /* end of real_main() */
> }
> 

... going to gnubg.c later.
still trying to get external.c compiled

(snip)

> Maybe defining the following will be enough:
> 
> #if WIN32
> #define inet_aton(ip,addr)  (addr)->s_addr = inet_addr(ip), 1
> #define inet_pton(fam,ip,addr) (addr)->s_addr = inet_addr(ip), 1
> #endif

that's done

> In sources that use *net* sockets, define:
> #if WIN32
> #define close(s) closesocket(sockfd)
> #endif
> 
> In sources that use *net* sockets, define:
> #if WIN32
> #define write(s,m,len) (send((s),(m),(len),0) == SOCKET_ERROR ? -1 : 
> (len))
> #endif
> 
> In sources that use *net* sockets, define:
> #if WIN32
> #define read(s,b,len) (rcv((s),(b),(len),0) == SOCKET_ERROR ? -1 : 
> (len))
> #endif
> 

setsockopt in winsock[2].h looks like:

SOCKET PASCAL accept(SOCKET,struct sockaddr*,int*);
int PASCAL bind(SOCKET,const struct sockaddr*,int);
int PASCAL closesocket(SOCKET);
int PASCAL connect(SOCKET,const struct sockaddr*,int);
int PASCAL ioctlsocket(SOCKET,long,u_long *);
int PASCAL getpeername(SOCKET,struct sockaddr*,int*);
int PASCAL getsockname(SOCKET,struct sockaddr*,int*);
int PASCAL getsockopt(SOCKET,int,int,char*,int*);
unsigned long PASCAL inet_addr(const char*);
DECLARE_STDCALL_P(char *) inet_ntoa(struct in_addr);
int PASCAL listen(SOCKET,int);
int PASCAL recv(SOCKET,char*,int,int);
int PASCAL recvfrom(SOCKET,char*,int,int,struct sockaddr*,int*);
int PASCAL send(SOCKET,const char*,int,int);
int PASCAL sendto(SOCKET,const char*,int,int,const struct sockaddr*,int);
int PASCAL setsockopt(SOCKET,int,int,const char*,int);
int PASCAL shutdown(SOCKET,int);
SOCKET PASCAL socket(int,int,int);

and no SIGPIPE in signal.h (mingw 2)   :-(

Nardy




reply via email to

[Prev in Thread] Current Thread [Next in Thread]