socket_xsb.h

00001 /* File:      socket_xsb.h
00002 ** Author(s): juliana, davulcu, kifer
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1999
00006 ** 
00007 ** XSB is free software; you can redistribute it and/or modify it under the
00008 ** terms of the GNU Library General Public License as published by the Free
00009 ** Software Foundation; either version 2 of the License, or (at your option)
00010 ** any later version.
00011 ** 
00012 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00013 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00015 ** more details.
00016 ** 
00017 ** You should have received a copy of the GNU Library General Public License
00018 ** along with XSB; if not, write to the Free Software Foundation,
00019 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020 **
00021 ** $Id: socket_xsb.h,v 1.4 2005/07/08 00:54:25 dwarren Exp $
00022 ** 
00023 */
00024 
00025 #ifndef __SOCKET_XSB_H__
00026 
00027 #define __SOCKET_XSB_H__
00028 
00029 #include "socket_defs_xsb.h"
00030 
00031 
00032 
00033 
00034 #ifdef WIN_NT
00035 
00036 #define BAD_SOCKET(sockfd)         sockfd==INVALID_SOCKET
00037 #define SOCKET_OP_FAILED(sockfd)   sockfd==SOCKET_ERROR
00038 #define IS_IP_ADDR(string)         inet_addr(string) != INADDR_NONE
00039 #define XSB_SOCKET_ERRORCODE       WSAGetLastError()
00040 #define FillWithZeros(addr)       ZeroMemory(&addr, sizeof(addr));
00041 #define EINPROGRESS               WSAEINPROGRESS
00042 #define EWOULDBLOCK               WSAEWOULDBLOCK
00043 #define SET_SOCKET_BLOCKING(fd, val) (ioctlsocket(fd, FIONBIO, (u_long FAR *)&val) == 0)
00044 #define GETSOCKOPT(fd,lvl,optname,optval,optlen) getsockopt(fd, lvl, optname, (char *)optval, optlen)
00045 #define SETSOCKOPT(fd,lvl,optname,optval,optlen) setsockopt(fd, lvl, optname, (char *)optval, optlen)
00046 
00047 
00048 #else /* UNIX */
00049 
00050 #define SOCKET          int
00051 #define SOCKADDR_IN     struct sockaddr_in /* in windows, but not Unix */
00052 #define PSOCKADDR       struct sockaddr *  /* in windows, but not Unix */
00053 #define closesocket               close
00054 #define XSB_SOCKET_ERRORCODE      errno
00055 #define BAD_SOCKET(sockfd)        sockfd<0
00056 #define SOCKET_OP_FAILED(sockfd)  sockfd<0
00057 #define IS_IP_ADDR(string)        inet_addr(string) != -1
00058 #define FillWithZeros(addr)       memset((char *)&addr, (int) 0, sizeof(addr));
00059 #define SET_SOCKET_BLOCKING(fd, val) (val \
00060                                       ? (fcntl(fd, F_SETFL, (fcntl(fd, F_GETFL, 0) | O_NONBLOCK)) != -1) \
00061                                       : (fcntl(fd, F_SETFL, (fcntl(fd, F_GETFL, 0) ^ O_NONBLOCK)) != -1))
00062 #define GETSOCKOPT(fd,lvl,optname,optval,optlen) getsockopt(fd, lvl, optname, (void *)optval, optlen)
00063 #define SETSOCKOPT(fd,lvl,optname,optval,optlen) setsockopt(fd, lvl, optname, (void *)optval, optlen)
00064 
00065 #endif
00066 
00067 
00068 
00069 #define MAXCONNECT 50        /* max number of connections per socket_select */
00070 
00071 /* the length of the XSB header that contains the info on the size of the
00072    subsequent message. Used by socket_send/socket_recv */
00073 #define XSB_MSG_HEADER_LENGTH  sizeof(int)
00074 
00075 /* These are used only by the readmsg function */
00076 #define SOCK_READMSG_FAILED  -1      /* failed socket call                  */
00077 #define SOCK_READMSG_EOF     -2      /* when EOF is reached                 */
00078 
00079 #endif /* __SOCKET_XSB_H__ */
00080 
00081 
00082 
00083 
00084 
00085 
00086 
00087 

Generated on Wed Jul 26 13:30:42 2006 for XSB by  doxygen 1.4.5