SocketBuffer.h 2.5 KB

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