Newer
Older
snipet / libsc / trunk / include / sc_socket.h
  1. /* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 :
  2. * =====================================================================
  3. * sc_socket.h
  4. * Copyright (c) 2003 - 2011 sys0tem
  5. * LICENSE :
  6. * LGPL (GNU Lesser General Public License - Version 3,29 June 2007)
  7. * http://www.gnu.org/copyleft/lesser.html
  8. * or
  9. * EPL (Eclipse Public License - v1.0)
  10. * http://www.eclipse.org/legal/epl-v10.html
  11. * =====================================================================
  12. */
  13. #ifndef __SC_SOCKET_H__
  14. #define __SC_SOCKET_H__
  15.  
  16. #include <sc_os.h>
  17.  
  18. #if (SC_isWindows)
  19. #ifndef _WIN32_WINNT
  20. #define _WIN32_WINNT 0x0501
  21. #endif /* _WIN32_WINNT */
  22. #include <windows.h>
  23. #include <winsock2.h>
  24. #include <ws2tcpip.h>
  25. #ifdef _MSV_VER
  26. #pragma comment(lib, "ws2_32.lib")
  27. #endif
  28. typedef SOCKET socket_t;
  29. #define socket_close(sockfd) closesocket(sockfd)
  30. #define SHUT_RD SD_RECEIVE
  31. #define SHUT_WR SD_SEND
  32. #define SHUT_RDWR SD_BOTH
  33. typedef long ssize_t;
  34. #else
  35. #include <sys/socket.h>
  36. #include <sys/types.h>
  37. #include <arpa/inet.h>
  38. #include <netinet/in.h>
  39. #include <netdb.h>
  40. #include <stdlib.h>
  41. #include <unistd.h>
  42. typedef int socket_t;
  43. #define socket_close(sockfd) close(sockfd)
  44. #define INVALID_SOCKET (-1)
  45. #define SOCKET_ERROR (-1)
  46.  
  47. #endif /* if (SC_isWindows) */
  48.  
  49. #include <sc_error.h>
  50.  
  51.  
  52. #ifdef __cplusplus
  53. extern "C" {
  54. #endif
  55.  
  56. #define SC_SOCKET_TEMPBUFF_SIZE (1024)
  57.  
  58. bool SC_Socket_init(void);
  59. int SC_getSocketError(void);
  60. socket_t SC_Socket_tcpConnect(const char*, const char*);
  61. socket_t SC_Socket_tcpListen(const char*, const char*, socklen_t*, int);
  62. socket_t SC_Socket_udpClient(const char*, const char*, struct sockaddr**, socklen_t*);
  63. socket_t SC_Socket_udpServer(const char*, const char*, socklen_t*);
  64. bool SC_Socket_close(socket_t sockfd);
  65.  
  66. #ifdef __cplusplus
  67. }
  68. #endif
  69.  
  70. #endif /* __SC_SOCKET_H__ */
  71.