/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 :
 * =====================================================================
 *  sc_socket.h
 *  Copyright (c)  2003 - 2011  sys0tem
 *  LICENSE :
 *	LGPL (GNU Lesser General Public License - Version 3,29 June 2007)
 *	http://www.gnu.org/copyleft/lesser.html
 *	or
 *	EPL (Eclipse Public License - v1.0)
 *	http://www.eclipse.org/legal/epl-v10.html
 * =====================================================================
 */
#ifndef __SC_SOCKET_H__
#define __SC_SOCKET_H__

#include <sc_os.h>

#if (SC_isWindows)
	#ifndef _WIN32_WINNT
		#define _WIN32_WINNT 0x0501
	#endif /* _WIN32_WINNT */
	#include <windows.h>
	#include <winsock2.h>
	#include <ws2tcpip.h>
	#ifdef _MSV_VER
		#pragma comment(lib, "ws2_32.lib")
	#endif
	typedef SOCKET socket_t;
	#define close(sockfd)	closesocket(sockfd)
	#define SHUT_RD			SD_RECEIVE
	#define SHUT_WR			SD_SEND
	#define SHUT_RDWR		SD_BOTH

#else
	#include <sys/socket.h>
	#include <sys/types.h>
	#include <arpa/inet.h>
	#include <netinet/in.h>
	#include <netdb.h>
	#include <stdlib.h>
	#include <unistd.h>
	typedef int socket_t;
	#define INVALID_SOCKET (-1)
	#define SOCKET_ERROR   (-1)

#endif	/* if (SC_isWindows) */

#include <sc_error.h>


#ifdef __cplusplus
extern "C" {
#endif

#define SC_SOCKET_TEMPBUFF_SIZE (1024)

bool SC_Socket_init(void);
int  SC_getSocketError(void);
socket_t SC_Socket_tcpConnect(const char*, const char*);
socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int);
socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*);
socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*);
bool     SC_Socket_close(socket_t sockfd);

#ifdef __cplusplus
}
#endif

#endif	/* __SC_SOCKET_H__ */

