• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2014 IBM Corp.
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * and Eclipse Distribution License v1.0 which accompany this distribution.
7  *
8  * The Eclipse Public License is available at
9  *    http://www.eclipse.org/legal/epl-v10.html
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 API and implementation and/or initial documentation
15  *    Ian Craggs, Allan Stockdill-Mander - SSL updates
16  *******************************************************************************/
17 
18 #if !defined(SOCKETBUFFER_H)
19 #define SOCKETBUFFER_H
20 
21 #if defined(WIN32) || defined(WIN64)
22 #include <winsock2.h>
23 #else
24 #include <sys/socket.h>
25 #endif
26 
27 #if defined(OPENSSL)
28 #include <openssl/ssl.h>
29 #endif
30 
31 #if defined(MBEDTLS)
32 #include "Clients.h"
33 #endif
34 
35 #if defined(WIN32) || defined(WIN64)
36 	typedef WSABUF iobuf;
37 #else
38 	typedef struct iovec iobuf;
39 #endif
40 
41 typedef struct
42 {
43 	int socket;
44 	unsigned int index;
45 	size_t headerlen;
46 	char fixed_header[5];	/**< header plus up to 4 length bytes */
47 	size_t buflen, 			/**< total length of the buffer */
48 		datalen; 			/**< current length of data in buf */
49 	char* buf;
50 } socket_queue;
51 
52 typedef struct
53 {
54 	int socket, count;
55 	size_t total;
56 #if defined(OPENSSL) || defined(MBEDTLS)
57 	SSL* ssl;
58 #endif
59 	size_t bytes;
60 	iobuf iovecs[5];
61 	int frees[5];
62 } pending_writes;
63 
64 #define SOCKETBUFFER_COMPLETE 0
65 #if !defined(SOCKET_ERROR)
66 	#define SOCKET_ERROR -1
67 #endif
68 #define SOCKETBUFFER_INTERRUPTED -22 /* must be the same value as TCPSOCKET_INTERRUPTED */
69 
70 void SocketBuffer_initialize(void);
71 void SocketBuffer_terminate(void);
72 void SocketBuffer_cleanup(int socket);
73 char* SocketBuffer_getQueuedData(int socket, size_t bytes, size_t* actual_len);
74 int SocketBuffer_getQueuedChar(int socket, char* c);
75 void SocketBuffer_interrupted(int socket, size_t actual_len);
76 char* SocketBuffer_complete(int socket);
77 void SocketBuffer_queueChar(int socket, char c);
78 
79 #if defined(OPENSSL) || defined(MBEDTLS)
80 void SocketBuffer_pendingWrite(int socket, SSL* ssl, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes);
81 #else
82 void SocketBuffer_pendingWrite(int socket, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes);
83 #endif
84 pending_writes* SocketBuffer_getWrite(int socket);
85 int SocketBuffer_writeComplete(int socket);
86 pending_writes* SocketBuffer_updateWrite(int socket, char* topic, char* payload);
87 
88 #endif
89