worker_end_tcp(s);
return protolayer_break(ctx, kr_error(ECONNRESET));
} else if (trimmed == 0) {
- session2_event(s, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(s);
return protolayer_break(ctx, kr_error(ECONNRESET));
}
if (uv_accept(master, (uv_stream_t *)client) != 0) {
/* close session, close underlying uv handles and
* deallocate (or return to memory pool) memory. */
- session2_event(s, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(s);
return;
}
int sa_len = sizeof(struct sockaddr_in6);
int ret = uv_tcp_getpeername(client, sa, &sa_len);
if (ret || sa->sa_family == AF_UNSPEC) {
- session2_event(s, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(s);
return;
}
sa = session2_get_sockname(s);
sa_len = sizeof(struct sockaddr_in6);
ret = uv_tcp_getsockname(client, sa, &sa_len);
if (ret || sa->sa_family == AF_UNSPEC) {
- session2_event(s, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(s);
return;
}
* Event types are used to distinguish different events that can be passed to
* sessions using `session2_event()`. */
#define PROTOLAYER_EVENT_MAP(XX) \
- XX(CLOSE) /**< Signal to gracefully close the session -
+ XX(CLOSE) /**< Sending this event closes the session gracefully -
* i.e. layers add their standard disconnection
* ceremony (e.g. `gnutls_bye()`). */\
- XX(FORCE_CLOSE) /**< Signal to forcefully close the
- * session - i.e. layers SHOULD NOT add
- * any disconnection ceremony, if
- * avoidable. */\
+ XX(FORCE_CLOSE) /**< Sending this event closes the session forcefully -
+ * i.e. layers SHOULD NOT add any disconnection
+ * ceremony, if avoidable. */\
XX(CONNECT_TIMEOUT) /**< Signal that a connection could not be
* established due to a timeout. */\
XX(GENERAL_TIMEOUT) /**< Signal that a general application-defined
void session2_event_after(struct session2 *s, enum protolayer_protocol protocol,
enum protolayer_event_type event, void *baton);
+/** Sends a `PROTOLAYER_EVENT_CLOSE` event to be processed by the protocol
+ * layers of the specified session. This function exists for readability
+ * reasons, to signal the intent that sending this event is used to actually
+ * close the session. */
+static inline void session2_close(struct session2 *s)
+{
+ session2_event(s, PROTOLAYER_EVENT_CLOSE, NULL);
+}
+
+/** Sends a `PROTOLAYER_EVENT_FORCE_CLOSE` event to be processed by the
+ * protocol layers of the specified session. This function exists for
+ * readability reasons, to signal the intent that sending this event is used to
+ * actually close the session. */
+static inline void session2_force_close(struct session2 *s)
+{
+ session2_event(s, PROTOLAYER_EVENT_FORCE_CLOSE, NULL);
+}
+
/** Performs initial setup of the specified `req`, using the session's protocol
* layers. Layers are processed in the `_UNWRAP` direction. */
void session2_init_request(struct session2 *s, struct kr_request *req);
}
if (addr->ip.sa_family != AF_UNSPEC) {
if (kr_fails_assert(addr->ip.sa_family == family)) {
- session2_event(s, PROTOLAYER_EVENT_FORCE_CLOSE, NULL);
+ session2_force_close(s);
return NULL;
}
if (socktype == SOCK_DGRAM) {
}
if (ret != 0) {
- session2_event(s, PROTOLAYER_EVENT_FORCE_CLOSE, NULL);
+ session2_force_close(s);
return NULL;
}
session2_waitinglist_finalize(session, KR_STATE_FAIL);
session2_tasklist_finalize(session, KR_STATE_FAIL);
worker_del_tcp_connected(peer);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
break;
}
session2_waitinglist_pop(session, true);
}
kr_assert(session2_tasklist_is_empty(session));
session2_waitinglist_retry(session, false);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return;
}
}
kr_assert(session2_tasklist_is_empty(session));
session2_waitinglist_retry(session, false);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return;
}
session2_event(session, PROTOLAYER_EVENT_CONNECT_FAIL, NULL);
}
kr_assert(session2_tasklist_is_empty(session));
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return;
}
};
ret = qr_task_send(task, session, &out_comm, task->pktbuf);
if (ret) {
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return ret;
}
* (ie. task->leading is true) */
worker_task_unref(t);
}
- session2_event(source_session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(source_session);
}
qr_task_unref(task);
* close connection to upstream. */
session2_tasklist_finalize(session, KR_STATE_FAIL);
worker_del_tcp_connected(session2_get_peer(session));
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return kr_error(EINVAL);
}
int ret = worker_add_tcp_waiting(addr, session);
if (ret < 0) {
free(conn);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return kr_error(EINVAL);
}
if (ret != 0) {
worker_del_tcp_waiting(addr);
free(conn);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return kr_error(EINVAL);
}
session2_timer_stop(session);
worker_del_tcp_waiting(addr);
free(conn);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
qry->server_selection.error(qry, task->transport, KR_SELECTION_TCP_CONNECT_FAILED);
return kr_error(EAGAIN);
}
session2_timer_stop(session);
worker_del_tcp_waiting(addr);
free(conn);
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return kr_error(EINVAL);
}
return kr_error(EINVAL);
session2_timer_stop(session);
- session2_event(session, PROTOLAYER_EVENT_FORCE_CLOSE, NULL);
+ session2_force_close(session);
return kr_ok();
}
worker_del_tcp_waiting(peer);
worker_del_tcp_connected(peer);
}
- session2_event(s, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(s);
}
}
* something gone wrong */
session2_waitinglist_finalize(session, KR_STATE_FAIL);
kr_assert(session2_tasklist_is_empty(session));
- session2_event(session, PROTOLAYER_EVENT_CLOSE, NULL);
+ session2_close(session);
return PROTOLAYER_EVENT_CONSUME;
}