aboutsummaryrefslogtreecommitdiff
path: root/src/SocketUtils.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/SocketUtils.h')
-rw-r--r--src/SocketUtils.h118
1 files changed, 31 insertions, 87 deletions
diff --git a/src/SocketUtils.h b/src/SocketUtils.h
index 7f5ddb4..9783351 100644
--- a/src/SocketUtils.h
+++ b/src/SocketUtils.h
@@ -2,9 +2,10 @@
@header SocketUtils.h
@date 1991
@author John Shalf
- @desc
-
- @enddesc
+ @desc
+ Header file for thorn Socket which defines routines
+ to deal with sockets.
+ @enddesc
@version $Header$
@@*/
@@ -16,96 +17,39 @@ extern "C"
{
#endif
-/* #if defined(ANSI) || defined(__STDC__) */
-#ifdef __STDC__
-/*
- TCP utilities library (1991)
- Last modification Dec 1995
-*/
-/*==================================================================
-** name: OpenClientSockTCP
-** purpose: Given the hostname of the server and the portnumber of the
-** service to connect to, it opens a TCP socket to the host and returns
-** the file descriptor of the socket.
-** parameters:
-** hostname: the name of the server host as a character string (not ip number)
-** port: The port number for the server.
-** returns:
-** integer file descriptor for low level io. Can convert to FILE *
-** using the fdopen() system call.
-**=================================================================*/
-int Socket_TCPOpenClientSock(const char *hostname, int port);
-int Socket_UDPOpenClientSock(const char *hostname, int port);
+#include "cctk.h" /* HAVE_WINSOCK2_H */
-/*==================================================================
-** name: OpenServerSockTCP
-** purpose: Opens a passive TCP connection on "port". After opening
-** the socket, the server is automatically set to listen on that socket.
-** The programmer need only call accept() to allow connections by clients.
-** parameters:
-** port: The port number for the server.
-** returns:
-** integer file descriptor for low level io. Needs to remain a file
-** descriptor to accept() client connections. Can convert the client
-** connection file descriptor to a FILE * using fdopen();
-**=================================================================*/
-int Socket_TCPOpenServerSock(int port);
-int Socket_UDPOpenServerSock(int port);
-
-/*==================================================================
-** name: TCPBlockingWrite
-** purpose: Handles error conditions when writing to a file descriptor.
-** If a buffer is too large to write in one block, this routine will
-** divide the buffer into two segments and recursively call itself to
-** send each of the halves.
-** parameters:
-** fd: file descriptor to write the buffer data to.
-** buffer: an array of bytes write to the file stream.
-** buflen: number of bytes in the buffer
-** returns:
-** either the number of characters written or constant describing
-** why the write failed.
-** notes: If you want the routine to print identifiable errors
-** to stderr, define PERRORS.
-**=================================================================*/
-int Socket_TCPBlockingWrite(int fd, char *buffer, int buflen);
-
-/*==================================================================
-** name: TCPBlockingRead
-** purpose: Handles error conditions when reading from a file descriptor.
-** With TCP stream connections, the record size of the recieved stream
-** may not coincide with the record written. This routine assembles
-** a fragmented record into a single array by blocking until buflen
-** characters are recieved, or write returns a premature EOF.
-** parameters:
-** fd: file descriptor to read the buffer data from.
-** buffer: an array of bytes read from the file stream.
-** buflen: number of bytes in the buffer
-** returns:
-** either the number of characters read into the buffer or constant describing
-** why the read failed.
-** notes: If you want the routine to print out identifiable errors
-** to stderr, define PERRORS.
-**=================================================================*/
-int Socket_TCPBlockingRead(int fd,char *buffer,int buflen);
-
-
-int Socket_SetNonBlocking(int sock);
+/* check what sockets type we have (Unix or Windows sockets)
+ Note that only MS compilers require to use Windows sockets
+ but gcc under Windows does not. */
+#if ! defined(HAVE_WINSOCK2_H) || defined(__GNUC__)
+#define SOCKET_HAVE_UNIX_SOCKETS 1
+#endif
+/* define the socket data type and constants denoting an invalid socket
+ and an error code returned from a socket call */
+#ifdef SOCKET_HAVE_UNIX_SOCKETS
+#define SOCKET int
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR -1
#else
-int Socket_TCPOpenClientSock();
-int Socket_TCPOpenServerSock();
-int Socket_TCPBlockingWrite();
-int Socket_TCPBlockingRead();
-int Socket_SetNonBlocking();
+/* the SOCKET type and the constants are defined in this header */
+#include <winsock2.h>
#endif
-#define PERRORS
-#ifndef __IN_HEADER
-#include <sys/types.h>
-#include <netinet/in.h>
-#endif
+int Socket_InitializeSocketLayer (void);
+SOCKET Socket_TCPOpenServerSocket (unsigned int port, unsigned int *hunt,
+ int backlog);
+SOCKET Socket_TCPOpenClientSocket (const char *hostname, unsigned int port);
+SOCKET Socket_UDPOpenServerSocket (unsigned int port);
+SOCKET Socket_UDPOpenClientSocket (const char *hostname, unsigned int port);
+void Socket_CloseSocket (SOCKET s);
+
+int Socket_TCPBlockingWrite (SOCKET s, const char *buffer, int buflen);
+int Socket_TCPBlockingRead (SOCKET s, char *buffer, int buflen);
+
+int Socket_SetNonBlocking (SOCKET s);
#ifdef __cplusplus
}