• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2009, 2022 IBM Corp., Ian Craggs 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 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 #include "Socket.h"
22 
23 #if defined(OPENSSL)
24 #include <openssl/ssl.h>
25 #endif
26 #if defined(MBEDTLS)
27 #include "Clients.h"
28 #endif
29 #if defined(_WIN32) || defined(_WIN64)
30 	typedef WSABUF iobuf;
31 #else
32 	typedef struct iovec iobuf;
33 #endif
34 
35 typedef struct
36 {
37 	SOCKET socket;
38 	unsigned int index;
39 	size_t headerlen;
40 	char fixed_header[5];	/**< header plus up to 4 length bytes */
41 	size_t buflen, 			/**< total length of the buffer */
42 		datalen; 			/**< current length of data in buf */
43 	char* buf;
44 } socket_queue;
45 
46 typedef struct
47 {
48 	SOCKET socket;
49 	int count;
50 	size_t total;
51 #if defined(OPENSSL) || defined(MBEDTLS)
52 	SSL* ssl;
53 #endif
54 	size_t bytes;
55 	iobuf iovecs[5];
56 	int frees[5];
57 } pending_writes;
58 
59 #define SOCKETBUFFER_COMPLETE 0
60 #if !defined(SOCKET_ERROR)
61 	#define SOCKET_ERROR -1
62 #endif
63 #define SOCKETBUFFER_INTERRUPTED -22 /* must be the same value as TCPSOCKET_INTERRUPTED */
64 
65 int SocketBuffer_initialize(void);
66 void SocketBuffer_terminate(void);
67 void SocketBuffer_cleanup(SOCKET socket);
68 char* SocketBuffer_getQueuedData(SOCKET socket, size_t bytes, size_t* actual_len);
69 int SocketBuffer_getQueuedChar(SOCKET socket, char* c);
70 void SocketBuffer_interrupted(SOCKET socket, size_t actual_len);
71 char* SocketBuffer_complete(SOCKET socket);
72 void SocketBuffer_queueChar(SOCKET socket, char c);
73 
74 #if defined(OPENSSL) || defined(MBEDTLS)
75 int SocketBuffer_pendingWrite(SOCKET socket, SSL* ssl, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes);
76 #else
77 int SocketBuffer_pendingWrite(SOCKET socket, int count, iobuf* iovecs, int* frees, size_t total, size_t bytes);
78 #endif
79 pending_writes* SocketBuffer_getWrite(SOCKET socket);
80 int SocketBuffer_writeComplete(SOCKET socket);
81 pending_writes* SocketBuffer_updateWrite(SOCKET socket, char* topic, char* payload);
82 
83 #endif
84