discuss-gnustep
[Top][All Lists]
Advanced

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

Re: NSStream and friends + NSPredicate, NSExpression and others


From: Andrew Sveikauskas
Subject: Re: NSStream and friends + NSPredicate, NSExpression and others
Date: Tue, 14 Feb 2006 15:54:08 -0500
User-agent: Mutt/1.4.2i

On Tue, Feb 14, 2006 at 02:04:36AM -0800, hns@computer.org wrote:
> This could especially be important for the mingw32 API which might have
> its special issues. I personally have no
> experience with that so I have used the standard POSIX socket(),
> select(), connect(), listen() calls - assuming a certain behaviour.

I just thought I'd throw my two cents on this one.

Winsock and Unix sockets are similar enough that you can write cross-platform
socket code like this:

#ifdef _WIN32
#include <winsock.h>
#else
#include <unistd.h>
#include <sys/socket.h>
/* ... all other headers - there are quite a few. */

/* Some typedefs and macros to make Unix sockets seem more like Win32. */

typedef int SOCKET;

#define INVALID_SOCKET  -1
#define SOCKET_ERROR    -1

#define closesocket     close
#define WSAStartup(x,y) 0
#endif

Then use Winsock semantics, namely:

1. Before calling any socket functions, call WSAStartup() exactly once.

2. Instead of using int for file descriptors, use SOCKET.

3. Don't call read() or write(), instead use send() and recv().

4. Don't use close(), use closesocket().

5. If a function returns a socket, it returns INVALID_SOCKET on error.  If it
returns an int under Unix, it returns SOCKET_ERROR on error.

5. Getting errors are tricky.  Unix of course uses errno, but Windows has
WSAGetLastError().  (You can create a strerror-like thing with FormatMessage())

6. If you want to set non-blocking, you want to use ioctlsocket() on Win32.

7. On Win32 there is no poll() but there is select().  Creating poll() like
functionality involves complicated tricks with WaitForMultipleObjectsEx().
I say complicated here because on WinNT AFAIK you can just pass socket handles
to this function, but 9x needs you to do some extra things which escape me
at the moment.

Just some rough notes from my limited experience porting socket apps to Winsock.

Andrew





reply via email to

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