Newer
Older
snipet / kyscript / trunk / lib / nstdc / include / nstdc_socket.h
/**
 * @file      nstdc_socket.h
 * @brief     ソケットを扱うモジュール
 * @author    Nomura Kei
 * @copyright 2003 - 2017  Nomura Kei
 * License: New BSD License (3-cclause BSD license)
 */
#ifndef NSTDC_SOCKET_H
#define NSTDC_SOCKET_H

#include <stddef.h>
#include <stdbool.h>

#include <nstdc.h>
#include <nstdc_os.h>


#if (nstdc_is_windows())
#include <ws2tcpip.h>
#ifdef _MSV_VER
	#pragma comment(lib, "ws2_32.lib")
#endif
#define SHUT_RD			SD_RECEIVE
#define SHUT_WR			SD_SEND
#define SHUT_RDWR		SD_BOTH

#else
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>

#endif


#ifdef __cplusplus
extern "C" {
#endif

#if (nstdc_is_windows())

#define socket(              domain, type, protocol)						\
		socket_win(          domain, type, protocol)

#define accept(              sockfd, addr, addrlen)							\
		accept(     (SOCKET) sockfd, addr, addrlen)

#define bind(                sockfd, addr, addrlen)							\
		bind(       (SOCKET) sockfd, addr, addrlen)

#define connect(             sockfd, addr, addrlen)							\
		connect(    (SOCKET) sockfd, addr, addrlen)

#define listen(              sockfd, backlog)								\
		listen(     (SOCKET) sockfd, backlog)

#define shutdown(            sockfd, how)									\
		shutdown(   (SOCKET) sockfd, how)

#define close(               sockfd)										\
		closesocket((SOCKET) sockfd)

#define recv(                sockfd, buf, len, flags)						\
		recv(       (SOCKET) sockfd, buf, len, flags)

#define recvfrom(            sockfd, buf, len, flags, src_addr, addrlen)	\
		recvfrom (  (SOCKET) sockfd, buf, len, flags, src_addr, addrlen)

#define send(                sockfd, buf, len, flags)						\
		send(       (SOCKET) sockfd, buf, len, flags)

#define sendto(              sockfd, buf, len, flags, dest_addr, addrlen)	\
		sendto(     (SOCKET) sockfd, buf, len, flags, dest_addr, addrlen)

#endif	/* if (nstdc_is_windows())	*/



#ifdef __cplusplus
}
#endif

#endif	/* NSTDC_SOCKET_H	*/