Blame src/socket.h

Packit b53373
#ifndef SOCKET_H
Packit b53373
#define SOCKET_H
Packit b53373
/*=========================================================================*\
Packit b53373
* Socket compatibilization module
Packit b53373
* LuaSocket toolkit
Packit b53373
*
Packit b53373
* BSD Sockets and WinSock are similar, but there are a few irritating
Packit b53373
* differences. Also, not all *nix platforms behave the same. This module
Packit b53373
* (and the associated usocket.h and wsocket.h) factor these differences and
Packit b53373
* creates a interface compatible with the io.h module.
Packit b53373
\*=========================================================================*/
Packit b53373
#include "io.h"
Packit b53373
Packit b53373
/*=========================================================================*\
Packit b53373
* Platform specific compatibilization
Packit b53373
\*=========================================================================*/
Packit b53373
#ifdef _WIN32
Packit b53373
#include "wsocket.h"
Packit b53373
#else
Packit b53373
#include "usocket.h"
Packit b53373
#endif
Packit b53373
Packit b53373
/*=========================================================================*\
Packit b53373
* The connect and accept functions accept a timeout and their
Packit b53373
* implementations are somewhat complicated. We chose to move
Packit b53373
* the timeout control into this module for these functions in
Packit b53373
* order to simplify the modules that use them. 
Packit b53373
\*=========================================================================*/
Packit b53373
#include "timeout.h"
Packit b53373
Packit b53373
/* we are lazy... */
Packit b53373
typedef struct sockaddr SA;
Packit b53373
Packit b53373
/*=========================================================================*\
Packit b53373
* Functions bellow implement a comfortable platform independent 
Packit b53373
* interface to sockets
Packit b53373
\*=========================================================================*/
Packit b53373
int socket_open(void);
Packit b53373
int socket_close(void);
Packit b53373
void socket_destroy(p_socket ps);
Packit b53373
void socket_shutdown(p_socket ps, int how); 
Packit b53373
int socket_sendto(p_socket ps, const char *data, size_t count, 
Packit b53373
        size_t *sent, SA *addr, socklen_t addr_len, p_timeout tm);
Packit b53373
int socket_recvfrom(p_socket ps, char *data, size_t count, 
Packit b53373
        size_t *got, SA *addr, socklen_t *addr_len, p_timeout tm);
Packit b53373
Packit b53373
void socket_setnonblocking(p_socket ps);
Packit b53373
void socket_setblocking(p_socket ps);
Packit b53373
Packit b53373
int socket_waitfd(p_socket ps, int sw, p_timeout tm);
Packit b53373
int socket_select(t_socket n, fd_set *rfds, fd_set *wfds, fd_set *efds, 
Packit b53373
        p_timeout tm);
Packit b53373
Packit b53373
int socket_connect(p_socket ps, SA *addr, socklen_t addr_len, p_timeout tm); 
Packit b53373
int socket_create(p_socket ps, int domain, int type, int protocol);
Packit b53373
int socket_bind(p_socket ps, SA *addr, socklen_t addr_len); 
Packit b53373
int socket_listen(p_socket ps, int backlog);
Packit b53373
int socket_accept(p_socket ps, p_socket pa, SA *addr, 
Packit b53373
        socklen_t *addr_len, p_timeout tm);
Packit b53373
Packit b53373
const char *socket_hoststrerror(int err);
Packit b53373
const char *socket_gaistrerror(int err);
Packit b53373
const char *socket_strerror(int err);
Packit b53373
Packit b53373
/* these are perfect to use with the io abstraction module 
Packit b53373
   and the buffered input module */
Packit b53373
int socket_send(p_socket ps, const char *data, size_t count, 
Packit b53373
        size_t *sent, p_timeout tm);
Packit b53373
int socket_recv(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
Packit b53373
int socket_write(p_socket ps, const char *data, size_t count, 
Packit b53373
        size_t *sent, p_timeout tm);
Packit b53373
int socket_read(p_socket ps, char *data, size_t count, size_t *got, p_timeout tm);
Packit b53373
const char *socket_ioerror(p_socket ps, int err);
Packit b53373
Packit b53373
int socket_gethostbyaddr(const char *addr, socklen_t len, struct hostent **hp);
Packit b53373
int socket_gethostbyname(const char *addr, struct hostent **hp);
Packit b53373
Packit b53373
#endif /* SOCKET_H */