Socket.h
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright (c) 2009, 2020 IBM Corp. and others
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v2.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  * https://www.eclipse.org/legal/epl-2.0/
10  * and the Eclipse Distribution License is available at
11  * http://www.eclipse.org/org/documents/edl-v10.php.
12  *
13  * Contributors:
14  * Ian Craggs - initial implementation and documentation
15  * Ian Craggs - async client updates
16  *******************************************************************************/
17 
18 #if !defined(SOCKET_H)
19 #define SOCKET_H
20 
21 #include <stdint.h>
22 #include <sys/types.h>
23 
24 #if defined(_WIN32) || defined(_WIN64)
25 #include <errno.h>
26 #include <winsock2.h>
27 #include <ws2tcpip.h>
28 #define MAXHOSTNAMELEN 256
29 #if !defined(SSLSOCKET_H)
30 #undef EAGAIN
31 #define EAGAIN WSAEWOULDBLOCK
32 #undef EINTR
33 #define EINTR WSAEINTR
34 #undef EINPROGRESS
35 #define EINPROGRESS WSAEINPROGRESS
36 #undef EWOULDBLOCK
37 #define EWOULDBLOCK WSAEWOULDBLOCK
38 #undef ENOTCONN
39 #define ENOTCONN WSAENOTCONN
40 #undef ECONNRESET
41 #define ECONNRESET WSAECONNRESET
42 #undef ETIMEDOUT
43 #define ETIMEDOUT WAIT_TIMEOUT
44 #endif
45 #define ioctl ioctlsocket
46 #define socklen_t int
47 #else
48 #define INVALID_SOCKET SOCKET_ERROR
49 #include <sys/socket.h>
50 #if !defined(_WRS_KERNEL)
51 #include <sys/param.h>
52 #include <sys/time.h>
53 #include <sys/select.h>
54 #include <sys/uio.h>
55 #else
56 #include <selectLib.h>
57 #endif
58 #include <netinet/in.h>
59 #include <netinet/tcp.h>
60 #include <arpa/inet.h>
61 #include <netdb.h>
62 #include <stdio.h>
63 #include <unistd.h>
64 #include <errno.h>
65 #include <fcntl.h>
66 #include <unistd.h>
67 #define ULONG size_t
68 #endif
69 
70 #include "mutex_type.h" /* Needed for mutex_type */
71 
73 #define TCPSOCKET_COMPLETE 0
74 #if !defined(SOCKET_ERROR)
75 
76  #define SOCKET_ERROR -1
77 #endif
78 
79 #define TCPSOCKET_INTERRUPTED -22
80 #define SSL_FATAL -3
81 
82 #if !defined(INET6_ADDRSTRLEN)
83 #define INET6_ADDRSTRLEN 46
84 #endif
85 
86 
87 #if !defined(max)
88 #define max(A,B) ( (A) > (B) ? (A):(B))
89 #endif
90 
91 #include "LinkedList.h"
92 
93 /*
94  * Network write buffers for an MQTT packet
95  */
96 typedef struct
97 {
98  int count;
99  char** buffers;
100  size_t* buflens;
101  int* frees;
102  uint8_t mask[4];
103 } PacketBuffers;
104 
105 
109 typedef struct
110 {
111  fd_set rset,
112  rset_saved;
113  int maxfdp1;
118  fd_set pending_wset;
119 } Sockets;
120 
121 
122 void Socket_outInitialize(void);
123 void Socket_outTerminate(void);
124 int Socket_getReadySocket(int more_work, struct timeval *tp, mutex_type mutex);
125 int Socket_getch(int socket, char* c);
126 char *Socket_getdata(int socket, size_t bytes, size_t* actual_len, int* rc);
127 int Socket_putdatas(int socket, char* buf0, size_t buf0len, PacketBuffers bufs);
128 void Socket_close(int socket);
129 #if defined(__GNUC__) && defined(__linux__)
130 /* able to use GNU's getaddrinfo_a to make timeouts possible */
131 int Socket_new(const char* addr, size_t addr_len, int port, int* socket, long timeout);
132 #else
133 int Socket_new(const char* addr, size_t addr_len, int port, int* socket);
134 #endif
135 
137 char* Socket_getpeer(int sock);
138 
141 
142 typedef void Socket_writeComplete(int socket, int rc);
144 
145 #endif /* SOCKET_H */
void Socket_addPendingWrite(int socket)
Definition: Socket.c:577
int count
Definition: Socket.h:98
void Socket_setWriteCompleteCallback(Socket_writeComplete *)
Definition: Socket.c:852
int Socket_getch(int socket, char *c)
Definition: Socket.c:332
List * write_pending
Definition: Socket.h:117
void Socket_outTerminate(void)
Definition: Socket.c:151
void Socket_clearPendingWrite(int socket)
Definition: Socket.c:587
int Socket_putdatas(int socket, char *buf0, size_t buf0len, PacketBuffers bufs)
Definition: Socket.c:505
void Socket_writeComplete(int socket, int rc)
Definition: Socket.h:142
char ** buffers
Definition: Socket.h:99
size_t * buflens
Definition: Socket.h:100
void Socket_close(int socket)
Definition: Socket.c:627
int Socket_new(const char *addr, size_t addr_len, int port, int *socket)
Definition: Socket.c:671
ListElement * cur_clientsds
Definition: Socket.h:115
fd_set rset_saved
Definition: Socket.h:111
#define mutex_type
Definition: mutex_type.h:22
fd_set pending_wset
Definition: Socket.h:118
int Socket_noPendingWrites(int socket)
Definition: Socket.c:417
char * Socket_getdata(int socket, size_t bytes, size_t *actual_len, int *rc)
Definition: Socket.c:370
int Socket_getReadySocket(int more_work, struct timeval *tp, mutex_type mutex)
Definition: Socket.c:242
int * frees
Definition: Socket.h:101
MQTTClient c
Definition: test10.c:1656
void Socket_outInitialize(void)
Definition: Socket.c:122
int maxfdp1
Definition: Socket.h:113
char * Socket_getpeer(int sock)
Definition: Socket.c:1058
List * connect_pending
Definition: Socket.h:116
enum MQTTReasonCodes rc
Definition: test10.c:1112
Definition: format.h:3618
List * clientsds
Definition: Socket.h:114


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:11