SocketBuffer.h 2.5 KB

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