| 1 |
#ifndef PROACTOR_RAW_CONNECTION_INTERNAL_H |
| 2 |
#define PROACTOR_RAW_CONNECTION_INTERNAL_H |
| 3 |
/* |
| 4 |
* |
| 5 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 6 |
* or more contributor license agreements. See the NOTICE file |
| 7 |
* distributed with this work for additional information |
| 8 |
* regarding copyright ownership. The ASF licenses this file |
| 9 |
* to you under the Apache License, Version 2.0 (the |
| 10 |
* "License"); you may not use this file except in compliance |
| 11 |
* with the License. You may obtain a copy of the License at |
| 12 |
* |
| 13 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 14 |
* |
| 15 |
* Unless required by applicable law or agreed to in writing, |
| 16 |
* software distributed under the License is distributed on an |
| 17 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 18 |
* KIND, either express or implied. See the License for the |
| 19 |
* specific language governing permissions and limitations |
| 20 |
* under the License. |
| 21 |
* |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifdef __cplusplus |
| 25 |
extern "C" { |
| 26 |
#endif |
| 27 |
|
| 28 |
enum { |
| 29 |
read_buffer_count = 16, |
| 30 |
write_buffer_count = 16 |
| 31 |
}; |
| 32 |
|
| 33 |
typedef enum { |
| 34 |
buff_rempty = 0, |
| 35 |
buff_unread = 1, |
| 36 |
buff_read = 2, |
| 37 |
buff_wempty = 4, |
| 38 |
buff_unwritten = 5, |
| 39 |
buff_written = 6 |
| 40 |
} buff_type; |
| 41 |
|
| 42 |
/* |
| 43 |
* r = read, w = write |
| 44 |
* init = initial |
| 45 |
* o = open - can read/write |
| 46 |
* d = draining - write draining |
| 47 |
* c = closing - shutdown pending |
| 48 |
* s = stopped (closed) |
| 49 |
*/ |
| 50 |
typedef enum { |
| 51 |
conn_wrong = -1, |
| 52 |
conn_init = 0, |
| 53 |
conn_ro_wo = 1, |
| 54 |
conn_ro_wd = 2, |
| 55 |
conn_ro_wc = 3, |
| 56 |
conn_ro_ws = 4, |
| 57 |
conn_rc_wo = 5, |
| 58 |
conn_rc_wd = 6, |
| 59 |
conn_rs_wo = 7, |
| 60 |
conn_rs_wd = 8, |
| 61 |
conn_rs_ws = 9, |
| 62 |
conn_fini = 10, |
| 63 |
} raw_conn_state; |
| 64 |
|
| 65 |
typedef enum { |
| 66 |
disc_init = 0, |
| 67 |
disc_drain_msg = 1, |
| 68 |
disc_read_msg = 2, |
| 69 |
disc_written_msg = 3, |
| 70 |
disc_fini = 4 |
| 71 |
} raw_disconnect_state; |
| 72 |
|
| 73 |
typedef uint16_t buff_ptr; // This is always the index+1 so that 0 can be special |
| 74 |
|
| 75 |
typedef struct pbuffer_t { |
| 76 |
uintptr_t context; |
| 77 |
char *bytes; |
| 78 |
uint32_t capacity; |
| 79 |
uint32_t size; |
| 80 |
uint32_t offset; |
| 81 |
buff_ptr next; |
| 82 |
uint8_t type; // For debugging |
| 83 |
} pbuffer_t; |
| 84 |
|
| 85 |
struct pn_raw_connection_t { |
| 86 |
pbuffer_t rbuffers[read_buffer_count]; |
| 87 |
pbuffer_t wbuffers[write_buffer_count]; |
| 88 |
pn_condition_t *condition; |
| 89 |
pn_collector_t *collector; |
| 90 |
pn_record_t *attachments; |
| 91 |
uint32_t unwritten_offset; |
| 92 |
uint16_t rbuffer_count; |
| 93 |
uint16_t wbuffer_count; |
| 94 |
|
| 95 |
buff_ptr rbuffer_first_empty; |
| 96 |
buff_ptr rbuffer_first_unused; |
| 97 |
buff_ptr rbuffer_last_unused; |
| 98 |
buff_ptr rbuffer_first_read; |
| 99 |
buff_ptr rbuffer_last_read; |
| 100 |
|
| 101 |
buff_ptr wbuffer_first_empty; |
| 102 |
buff_ptr wbuffer_first_towrite; |
| 103 |
buff_ptr wbuffer_last_towrite; |
| 104 |
buff_ptr wbuffer_first_written; |
| 105 |
buff_ptr wbuffer_last_written; |
| 106 |
|
| 107 |
uint8_t state; // really raw_conn_state |
| 108 |
uint8_t disconnect_state; // really raw_disconnect_state |
| 109 |
|
| 110 |
bool rrequestedbuffers; |
| 111 |
bool wrequestedbuffers; |
| 112 |
|
| 113 |
bool rpending; |
| 114 |
bool wpending; |
| 115 |
bool rclosedpending; |
| 116 |
bool wclosedpending; |
| 117 |
bool disconnectpending; |
| 118 |
bool wakepending; |
| 119 |
}; |
| 120 |
|
| 121 |
/* |
| 122 |
* Raw connection internal API |
| 123 |
*/ |
| 124 |
bool pni_raw_validate(pn_raw_connection_t *conn); |
| 125 |
void pni_raw_connected(pn_raw_connection_t *conn); |
| 126 |
void pni_raw_connect_failed(pn_raw_connection_t *conn); |
| 127 |
void pni_raw_wake(pn_raw_connection_t *conn); |
| 128 |
void pni_raw_close(pn_raw_connection_t *conn); |
| 129 |
void pni_raw_read_close(pn_raw_connection_t *conn); |
| 130 |
void pni_raw_write_close(pn_raw_connection_t *conn); |
| 131 |
void pni_raw_read(pn_raw_connection_t *conn, int sock, long (*recv)(int, void*, size_t), void (*set_error)(pn_raw_connection_t *, const char *, int)); |
| 132 |
void pni_raw_write(pn_raw_connection_t *conn, int sock, long (*send)(int, const void*, size_t), void (*set_error)(pn_raw_connection_t *, const char *, int)); |
| 133 |
void pni_raw_process_shutdown(pn_raw_connection_t *conn, int sock, int (*shutdown_rd)(int), int (*shutdown_wr)(int)); |
| 134 |
bool pni_raw_can_read(pn_raw_connection_t *conn); |
| 135 |
bool pni_raw_can_write(pn_raw_connection_t *conn); |
| 136 |
pn_event_t *pni_raw_event_next(pn_raw_connection_t *conn); |
| 137 |
void pni_raw_initialize(pn_raw_connection_t *conn); |
| 138 |
void pni_raw_finalize(pn_raw_connection_t *conn); |
| 139 |
|
| 140 |
#ifdef __cplusplus |
| 141 |
} |
| 142 |
#endif |
| 143 |
|
| 144 |
#endif // PROACTOR_RAW_CONNECTION_INTERNAL_H |