Harlequin RIP SDK
psock.c File Reference

Socket related utility functions for Windows. See psock.h. More...

#include <windows.h>
#include <winsock.h>
#include <stdio.h>
#include <string.h>
#include "skinkit.h"
#include "psock.h"
#include "file.h"

Functions

static int32 map_errno (int err)
 Maps platform dependent error codes to platform independent error codes.
 
int32 PKSocketInit (int32 *pError)
 Performs any platform-specific initialization required to use sockets. More...
 
int32 PKSocketFinalize (int32 *pError)
 Performs any platform-specific finalization required to use sockets. More...
 
DEVICE_FILEDESCRIPTOR PKOpenServerSocket (int32 port, int32 *pError)
 Opens a socket and sets it to listen for connections. More...
 
DEVICE_FILEDESCRIPTOR PKOpenClientSocket (const uint8 *pbzAddr, int32 port, int32 *pError)
 Opens a socket connection using the specified address and port. More...
 
DEVICE_FILEDESCRIPTOR PKAcceptConnection (DEVICE_FILEDESCRIPTOR descriptor, int32 *pError)
 Blocks waiting for an incoming connection. More...
 
int32 PKReadSocket (DEVICE_FILEDESCRIPTOR descriptor, uint8 *buff, int32 len, int32 *pError)
 Reads data from a socket. More...
 
int32 PKWriteSocket (DEVICE_FILEDESCRIPTOR descriptor, uint8 *buff, int32 len, int32 *pError)
 Writes data to a socket. More...
 
int32 PKCloseSocket (DEVICE_FILEDESCRIPTOR descriptor, int32 *pError)
 Closes a socket. More...
 

Detailed Description

Socket related utility functions for Windows. See psock.h.

Function Documentation

◆ PKAcceptConnection()

DEVICE_FILEDESCRIPTOR PKAcceptConnection ( DEVICE_FILEDESCRIPTOR  descriptor,
int32 pError 
)

Blocks waiting for an incoming connection.

Parameters
[in]descriptorSocket descriptor, as returned by PKOpenSocket()
[out]pErrorSet to an error code if operations fails
Returns
non-negative socket descriptor for connection on success, -1 on failure

◆ PKCloseSocket()

int32 PKCloseSocket ( DEVICE_FILEDESCRIPTOR  descriptor,
int32 pError 
)

Closes a socket.

Parameters
[in]descriptorSocket descriptor, as returned by PKAcceptConnection()
[out]pErrorSet to an error code if operations fails
Returns
0 on success, -1 on failure

◆ PKOpenClientSocket()

DEVICE_FILEDESCRIPTOR PKOpenClientSocket ( const uint8 pbzAddr,
int32  port,
int32 pError 
)

Opens a socket connection using the specified address and port.

Parameters
[in]pbzAddrThe IP address to use when connecting.
[in]portPort number
[out]pErrorSet to an error code if operations fails
Returns
non-negative socket descriptor on success, -1 on failure

◆ PKOpenServerSocket()

DEVICE_FILEDESCRIPTOR PKOpenServerSocket ( int32  port,
int32 pError 
)

Opens a socket and sets it to listen for connections.

Once a connection is established use PKAcceptConnection() to accept it.

Parameters
[in]portPort number
[out]pErrorSet to an error code if operations fails
Returns
non-negative socket descriptor on success, -1 on failure

◆ PKReadSocket()

int32 PKReadSocket ( DEVICE_FILEDESCRIPTOR  descriptor,
uint8 buff,
int32  len,
int32 pError 
)

Reads data from a socket.

Parameters
[in]descriptorSocket descriptor, as returned by PKAcceptConnection()
[in]buffBuffer to read data into
[in]lenSize of buff
[out]pErrorSet to an error code if operations fails
Returns
number of bytes read, -1 on failure

◆ PKSocketFinalize()

int32 PKSocketFinalize ( int32 pError)

Performs any platform-specific finalization required to use sockets.

Parameters
[out]pErrorSet to an error code if operations fails
Returns
0 on success, -1 on failure

◆ PKSocketInit()

int32 PKSocketInit ( int32 pError)

Performs any platform-specific initialization required to use sockets.

Parameters
[out]pErrorSet to an error code if operations fails
Returns
0 on success, -1 on failure

◆ PKWriteSocket()

int32 PKWriteSocket ( DEVICE_FILEDESCRIPTOR  descriptor,
uint8 buff,
int32  len,
int32 pError 
)

Writes data to a socket.

Parameters
[in]descriptorSocket descriptor, as returned by PKAcceptConnection()
[in]buffBuffer of data to write
[in]lenSize of buff
[out]pErrorSet to an error code if operations fails
Returns
number of bytes written, -1 on failure