2 * Ring buffer I/O for sslThroughput test.
5 #ifndef _RING_BUFFER_IO_
6 #define _RING_BUFFER_IO_
11 #include <Security/SecureTransport.h>
17 /* Reasonable defaults for Ring Buffer params */
18 #define DEFAULT_NUM_RB_BUFS 16
19 #define DEFAULT_BUF_RB_SIZE 2048 /* in the ring buffers */
22 /* one element in a ring buffer */
24 size_t validBytes
; // bytes written and not yet consumed
25 size_t readOffset
; // next byte to be read from this offset
26 size_t capacity
; // mallocd size of buf
31 * A ring buffer shared between one writer thread and one reader thread.
32 * Per the DeMoney Theorem, we don't need to provide any locking between
33 * the two threads if we have the appropriate protocol, which is as follows:
35 * -- the RingElements at which the reader and writer are currently
36 * processing are indicated by readerDex and writerDex.
37 * -- the writer thread never advances writerDex to a RingElement
38 * currently in use by the reader thread.
39 * -- the reader thread can advance to a RingElement in use by
40 * the writer thread, but it can't read from that RingElement
41 * until the writer thread has advanced past that RingElement.
45 RingElement
*elements
;
46 unsigned writerDex
; // writer thread is working on this one
47 unsigned readerDex
; // read thread is working on this one
48 const char *bufName
; // e.g. serverToClient
51 * Flag to emulate closing of socket. There's only one since the thread
52 * that sets this presumably will not be reading from or writing to
53 * this RingBuffer again; the "other" thread will detect this and abort
60 * A pair of RingBuffer ptrs suitable for use as the SSLConnectionRef
61 * for ringReadFunc() and ringWriteFunc().
78 * The "I/O" callbacks for SecureTransport.
79 * The SSLConnectionRef is a RingBuffers *.
81 OSStatus
ringReadFunc(
82 SSLConnectionRef connRef
,
84 size_t *dataLen
); /* IN/OUT */
85 OSStatus
ringWriteFunc(
86 SSLConnectionRef connRef
,
88 size_t *dataLen
); /* IN/OUT */
90 /* close both sides of a RingBuffers */
91 void ringBuffersClose(
94 /* to coordinate stdio from multi threads */
95 extern pthread_mutex_t printfMutex
;
101 #endif /* _RING_BUFFER_IO_ */