added:
* win32_slim.h: includes the minimal version of windows.h modified: * cthread: added lock_t c++ class * os: added getUserName() * socket: modified socket_len_t to sk_len_t to better follow naming convetions in file * str: added operator std::string() to str_t
This commit is contained in:
parent
7fdc8b5301
commit
bce93361b1
16 changed files with 187 additions and 70 deletions
28
socket.h
28
socket.h
|
|
@ -15,15 +15,17 @@ extern "C" {
|
|||
|
||||
#if SOCK_WINDOWS
|
||||
#pragma warning(disable:4996) // _WINSOCK_DEPRECATED_NO_WARNINGS
|
||||
#include "win32_slim.h"
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
typedef SOCKET socket_t;
|
||||
typedef int socket_len_t;
|
||||
typedef int sk_len_t;
|
||||
#elif SOCK_POSIX
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
typedef int socket_t;
|
||||
typedef uint32_t socket_len_t;
|
||||
typedef uint32_t sk_len_t;
|
||||
#define INVALID_SOCKET (-1)
|
||||
#define SOCKET_ERROR (-1)
|
||||
#endif
|
||||
|
|
@ -61,7 +63,7 @@ bool skClose(socket_t sock);
|
|||
// Associate a local address with a socket
|
||||
bool skBind(socket_t sock, const char *ip, uint16_t port);
|
||||
// Associate a local address with a socket
|
||||
bool skBindPro(socket_t sock, const sk_addr_t *name, socket_len_t namelen);
|
||||
bool skBindPro(socket_t sock, const sk_addr_t *name, sk_len_t namelen);
|
||||
|
||||
// Place a socket in a state in which it is listening for an incoming connection
|
||||
bool skListen(socket_t sock);
|
||||
|
|
@ -71,29 +73,29 @@ bool skListenPro(socket_t sock, int backlog);
|
|||
// Permits an incoming connection attempt on a socket
|
||||
socket_t skAccept(socket_t sock);
|
||||
// Permits an incoming connection attempt on a socket
|
||||
socket_t skAcceptPro(socket_t sock, sk_addr_t *addr, socket_len_t *addrlen);
|
||||
socket_t skAcceptPro(socket_t sock, sk_addr_t *addr, sk_len_t *addrlen);
|
||||
|
||||
// Connects to a server (e.g. "127.0.0.1" or "google.com") with a port(e.g. 1234), returns true on success
|
||||
bool skConnect(socket_t sock, const char *server, unsigned short server_port);
|
||||
// Connects to a server, returns true on success
|
||||
bool skConnectPro(socket_t sock, const sk_addr_t *name, socket_len_t namelen);
|
||||
bool skConnectPro(socket_t sock, const sk_addr_t *name, sk_len_t namelen);
|
||||
|
||||
// Sends data on a socket, returns true on success
|
||||
int skSend(socket_t sock, const char *buf, int len);
|
||||
int skSend(socket_t sock, const void *buf, int len);
|
||||
// Sends data on a socket, returns true on success
|
||||
int skSendPro(socket_t sock, const char *buf, int len, int flags);
|
||||
int skSendPro(socket_t sock, const void *buf, int len, int flags);
|
||||
// Sends data to a specific destination
|
||||
int skSendTo(socket_t sock, const char *buf, int len, const sk_addrin_t *to);
|
||||
int skSendTo(socket_t sock, const void *buf, int len, const sk_addrin_t *to);
|
||||
// Sends data to a specific destination
|
||||
int skSendToPro(socket_t sock, const char *buf, int len, int flags, const sk_addr_t *to, int tolen);
|
||||
int skSendToPro(socket_t sock, const void *buf, int len, int flags, const sk_addr_t *to, int tolen);
|
||||
// Receives data from a socket, returns byte count on success, 0 on connection close or -1 on error
|
||||
int skReceive(socket_t sock, char *buf, int len);
|
||||
int skReceive(socket_t sock, void *buf, int len);
|
||||
// Receives data from a socket, returns byte count on success, 0 on connection close or -1 on error
|
||||
int skReceivePro(socket_t sock, char *buf, int len, int flags);
|
||||
int skReceivePro(socket_t sock, void *buf, int len, int flags);
|
||||
// Receives a datagram and stores the source address.
|
||||
int skReceiveFrom(socket_t sock, char *buf, int len, sk_addrin_t *from);
|
||||
int skReceiveFrom(socket_t sock, void *buf, int len, sk_addrin_t *from);
|
||||
// Receives a datagram and stores the source address.
|
||||
int skReceiveFromPro(socket_t sock, char *buf, int len, int flags, sk_addr_t *from, socket_len_t *fromlen);
|
||||
int skReceiveFromPro(socket_t sock, void *buf, int len, int flags, sk_addr_t *from, sk_len_t *fromlen);
|
||||
|
||||
// Checks that a opened socket is valid, returns true on success
|
||||
bool skIsValid(socket_t sock);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue