43 #if defined(COMPILE_ON_WINDOWS) || (defined(COMPILE_ON_MINGW) && !defined(OS2))
45 #define KVI_INVALID_SOCKET INVALID_SOCKET
50 #if defined(COMPILE_ON_MINGW)
51 #ifndef IPV6_PROTECTION_LEVEL
52 #define IPV6_PROTECTION_LEVEL 23
53 #define PROTECTION_LEVEL_UNRESTRICTED 10
54 #define PROTECTION_LEVEL_DEFAULT 20
55 #define PROTECTION_LEVEL_RESTRICTED 30
59 #define KVI_IPV6_PROTECTION_LEVEL IPV6_PROTECTION_LEVEL
60 #define KVI_PROTECTION_LEVEL_RESTRICTED PROTECTION_LEVEL_RESTRICTED
61 #define KVI_PROTECTION_LEVEL_DEFAULT PROTECTION_LEVEL_DEFAULT
62 #define KVI_PROTECTION_LEVEL_UNRESTRICTED PROTECTION_LEVEL_UNRESTRICTED
63 #define KVI_IPPROTO_IPV6 IPPROTO_IPV6
68 #include <sys/types.h>
69 #include <sys/socket.h>
70 #include <netinet/tcp.h>
71 #include <netinet/in.h>
75 #define KVI_INVALID_SOCKET (-1)
80 #define MSG_NOSIGNAL 0
87 #define KVI_SOCKET_PF_INET PF_INET
88 #define KVI_SOCKET_PF_INET6 PF_INET6
89 #define KVI_SOCKET_PF_UNIX PF_UNIX
91 #define KVI_SOCKET_TYPE_STREAM SOCK_STREAM
92 #define KVI_SOCKET_TYPE_DGRAM SOCK_DGRAM
94 #define KVI_SOCKET_PROTO_TCP 0
106 #define kvi_socket_open kvi_socket_create
110 #ifdef COMPILE_ON_MAC
117 setsockopt(fd, SOL_SOCKET, SO_NOSIGPIPE, (
void *)&set,
sizeof(
int));
148 #define kvi_socket_close kvi_socket_destroy
152 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
167 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
168 unsigned long arg = 1;
169 return (ioctlsocket(sock, FIONBIO, (
unsigned long FAR *)&arg) == 0);
171 return (fcntl(sock, F_SETFL, O_NONBLOCK) == 0);
183 return (::bind(sock, sa, salen) == 0);
196 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
197 return (WSAConnect(sock, sa, salen, 0, 0, 0, 0) == 0);
199 return (::
connect(sock, sa, salen) == 0);
205 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
206 return ((err == WSAEINPROGRESS) || (err == WSAEWOULDBLOCK));
208 return (err == EINPROGRESS);
214 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
215 return ((err == WSAEWOULDBLOCK) || (err == EINTR) || (err == EAGAIN));
217 return ((err == EINTR) || (err == EAGAIN));
230 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
233 return (
kvi_socket_t)::accept(sock, sa, (socklen_t *)salen);
246 return (::listen(sock, backlog) == 0);
260 return ::select(nhpo, r, w, e, t);
271 #define kvi_socket_write kvi_socket_send
276 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
277 return ::send(sock, (
const char *)buf, size, 0);
279 return ::send(sock, buf, size,
MSG_NOSIGNAL | MSG_DONTWAIT);
291 #define kvi_socket_read kvi_socket_recv
296 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
297 iReceived = ::recv(sock, (
char *)buf, maxlen, 0);
314 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
315 return (::getsockopt(sock, level, optname, (
char FAR *)optval, optlen) == 0);
317 return (::getsockopt(sock, level, optname, optval, (socklen_t *)optlen) == 0);
330 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
331 return (::setsockopt(sock, level, optname, (
char FAR *)optval, optlen) == 0);
333 return (::setsockopt(sock, level, optname, optval, optlen) == 0);
361 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
362 return (::getsockname(sock, addr, addrlen) == 0);
364 return (::getsockname(sock, addr, (socklen_t *)addrlen) == 0);
370 #if defined(COMPILE_ON_WINDOWS) || defined(COMPILE_ON_MINGW)
371 return WSAGetLastError();
377 #endif //_KVI_SOCKET_H_
int kvi_socket_t
Definition: kvi_sockettype.h:40
#define KVI_INVALID_SOCKET
(defined(COMPILE_ON_WINDOWS) || (defined(COMPILE_ON_MINGW) && !defined(OS2))
Definition: kvi_socket.h:75
kvi_socket_t kvi_socket_create(int pf, int type, int proto)
Definition: kvi_socket.h:108
connect(m_pFtp, SIGNAL(commandFinished(int, bool)), this, SLOT(slotCommandFinished(int, bool)))
bool kvi_socket_isValid(kvi_socket_t sock)
Definition: kvi_socket.h:136
bool kvi_socket_bind(kvi_socket_t sock, const struct sockaddr *sa, int salen)
Definition: kvi_socket.h:181
bool kvi_socket_listen(kvi_socket_t sock, int backlog)
Definition: kvi_socket.h:244
int kvi_socket_select(int nhpo, fd_set *r, fd_set *w, fd_set *e, struct timeval *t)
Definition: kvi_socket.h:258
bool kvi_socket_setNonBlocking(kvi_socket_t sock)
Definition: kvi_socket.h:165
kvi_socket_t kvi_socket_accept(kvi_socket_t sock, struct sockaddr *sa, int *salen)
Definition: kvi_socket.h:228
#define MSG_NOSIGNAL
(defined(COMPILE_ON_WINDOWS) || (defined(COMPILE_ON_MINGW) && !defined(OS2))
Definition: kvi_socket.h:80
QString type()
Definition: KviRuntimeInfo.cpp:646
#define e
Definition: detector.cpp:69
bool kvi_socket_recoverableError(int err)
Definition: kvi_socket.h:212
unsigned long long int kvi_u64_t
Definition: kvi_inttypes.h:66
int kvi_socket_error()
Definition: kvi_socket.h:368
int kvi_socket_send(kvi_socket_t sock, const void *buf, int size)
Definition: kvi_socket.h:273
bool kvi_socket_getsockname(kvi_socket_t sock, struct sockaddr *addr, int *addrlen)
Definition: kvi_socket.h:359
bool kvi_socket_recoverableConnectError(int err)
Definition: kvi_socket.h:203
void kvi_socket_destroy(kvi_socket_t sock)
Definition: kvi_socket.h:150
int kvi_socket_recv(kvi_socket_t sock, void *buf, int maxlen)
Definition: kvi_socket.h:293
QHashIterator< int, QFile * > t(getDict)
bool kvi_socket_setsockopt(kvi_socket_t sock, int level, int optname, const void *optval, int optlen)
Definition: kvi_socket.h:328
KVILIB_API kvi_u64_t g_uOutgoingTraffic
Definition: kvi_socket.cpp:30
#define r
Definition: detector.cpp:82
bool kvi_socket_connect(kvi_socket_t sock, const struct sockaddr *sa, int salen)
Definition: kvi_socket.h:194
#define w
Definition: detector.cpp:87
void kvi_socket_flushTrafficCounters()
Definition: kvi_socket.h:130
KVILIB_API kvi_u64_t g_uIncomingTraffic
Definition: kvi_socket.cpp:31
void set(void *dst_ptr, char c, int len)
Initializes len bytes of memory starting from dst_ptr to c.
Definition: KviMemory.h:152
This file contains compile time settings.
bool kvi_socket_getsockopt(kvi_socket_t sock, int level, int optname, void *optval, int *optlen)
Definition: kvi_socket.h:312
#define KVILIB_API
Definition: kvi_settings.h:125