aboutsummaryrefslogtreecommitdiff
path: root/src/SocketUtils.h
blob: 9783351e26a8bc0c8bf92faa1dcdd29aa9af11b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
 /*@@
   @header    SocketUtils.h
   @date      1991
   @author    John Shalf
   @desc
              Header file for thorn Socket which defines routines
              to deal with sockets.
   @enddesc
   @version   $Header$
 @@*/

#ifndef _SOCKET_SOCKETUTILS_H_
#define _SOCKET_SOCKETUTILS_H_ 1

#ifdef __cplusplus
extern "C"
{
#endif

#include "cctk.h"     /* HAVE_WINSOCK2_H */

/* 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
/* the SOCKET type and the constants are defined in this header */
#include <winsock2.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
}
#endif

#endif /* _SOCKET_SOCKETUTILS_H */