-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PROTON-2748: Raw connection async close fix and tests. #402
base: main
Are you sure you want to change the base?
Changes from all commits
f73813a
7c6fc14
63985a9
4529406
546f046
9c83182
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,9 +134,11 @@ void pni_raw_write_close(pn_raw_connection_t *conn); | |
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)); | ||
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)); | ||
void pni_raw_process_shutdown(pn_raw_connection_t *conn, int sock, int (*shutdown_rd)(int), int (*shutdown_wr)(int)); | ||
void pni_raw_async_disconnect(pn_raw_connection_t *conn); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is a new event going to the raw connection state machine maybe there should be a new test for this event in raw_connection_test. |
||
bool pni_raw_can_read(pn_raw_connection_t *conn); | ||
bool pni_raw_can_write(pn_raw_connection_t *conn); | ||
pn_event_t *pni_raw_event_next(pn_raw_connection_t *conn); | ||
bool pni_raw_batch_has_events(pn_raw_connection_t *conn); | ||
void pni_raw_initialize(pn_raw_connection_t *conn); | ||
void pni_raw_finalize(pn_raw_connection_t *conn); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,12 +669,14 @@ bool pni_raw_can_write(pn_raw_connection_t *conn) { | |
return !pni_raw_wdrained(conn) && conn->wbuffer_first_towrite; | ||
} | ||
|
||
pn_event_t *pni_raw_event_next(pn_raw_connection_t *conn) { | ||
bool pni_raw_batch_has_events(pn_raw_connection_t *conn) { | ||
// If collector empty, advance state machine as necessary and generate next event. | ||
// Return true if at least one event is available. | ||
assert(conn); | ||
do { | ||
pn_event_t *event = pn_collector_next(conn->collector); | ||
pn_event_t *event = pn_collector_peek(conn->collector); | ||
if (event) { | ||
return pni_log_event(conn, event); | ||
return true; | ||
} else if (conn->connectpending) { | ||
pni_raw_put_event(conn, PN_RAW_CONNECTION_CONNECTED); | ||
conn->connectpending = false; | ||
|
@@ -716,11 +718,20 @@ pn_event_t *pni_raw_event_next(pn_raw_connection_t *conn) { | |
pni_raw_put_event(conn, PN_RAW_CONNECTION_NEED_READ_BUFFERS); | ||
conn->rrequestedbuffers = true; | ||
} else { | ||
return NULL; | ||
return false; | ||
} | ||
} while (true); | ||
} | ||
|
||
pn_event_t *pni_raw_event_next(pn_raw_connection_t *conn) { | ||
if (pni_raw_batch_has_events(conn)) { | ||
pn_event_t* event = pn_collector_next(conn->collector); | ||
assert(event); | ||
return pni_log_event(conn, event); | ||
} | ||
return NULL; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I would refactor pni_raw_event_next differently:
Just in case it's not clear the do ... while (true) is a bit of a red herring and somewhat bad coding on my part in that there is never more than one effective pass through the loop. There can be 2 but that if only if there was no initial event. So it make more sense really to separate out the event generating logic. Hope that is clear enough. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done with has_events(). |
||
void pni_raw_read_close(pn_raw_connection_t *conn) { | ||
// If already fully closed nothing to do | ||
if (pni_raw_rwclosed(conn)) { | ||
|
@@ -781,6 +792,22 @@ void pni_raw_close(pn_raw_connection_t *conn) { | |
} | ||
} | ||
|
||
void pni_raw_async_disconnect(pn_raw_connection_t *conn) { | ||
if (pni_raw_rwclosed(conn)) | ||
return; | ||
|
||
if (!pni_raw_rclosed(conn)) { | ||
conn->state = pni_raw_new_state(conn, conn_read_closed); | ||
conn->rclosedpending = true; | ||
} | ||
if (!pni_raw_wclosed(conn)) { | ||
pni_raw_release_buffers(conn); | ||
conn->state = pni_raw_new_state(conn, conn_write_closed); | ||
conn->wclosedpending = true; | ||
} | ||
pni_raw_disconnect(conn); | ||
} | ||
|
||
bool pn_raw_connection_is_read_closed(pn_raw_connection_t *conn) { | ||
assert(conn); | ||
return pni_raw_rclosed(conn); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where did this logic go? It seems no longer to be anywhere. Is it no longer needed? Specifically the check against the disconnected event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic was solely there to identify edge cases where the epoll-specific code could not be sure if the state machine was up to date. In which case a non-application call to pni_raw_batch_next() would update the state machine but a resulting event would have to be put back into the collector.
The new pni_raw_batch_has_events() updates the state machine and has no side effects to the event stream, so the check for batch_empty is no longer needed.