- print_packet(c->utcp, "send", &hdr, sizeof hdr);
- c->utcp->send(c->utcp, &hdr, sizeof hdr);
+ print_packet(c->utcp, "send", &hdr, sizeof(hdr));
+ c->utcp->send(c->utcp, &hdr, sizeof(hdr));
+ return true;
+}
+
+// Closes all the opened connections
+void utcp_abort_all_connections(struct utcp *utcp) {
+ if(!utcp) {
+ errno = EINVAL;
+ return;
+ }
+
+ for(int i = 0; i < utcp->nconnections; i++) {
+ struct utcp_connection *c = utcp->connections[i];
+
+ if(c->reapable || c->state == CLOSED) {
+ continue;
+ }
+
+ utcp_recv_t old_recv = c->recv;
+
+ reset_connection(c);
+
+ if(old_recv) {
+ errno = 0;
+ old_recv(c, NULL, 0);
+ }
+ }
+
+ return;
+}
+
+int utcp_close(struct utcp_connection *c) {
+ if(utcp_shutdown(c, SHUT_RDWR) && errno != ENOTCONN) {
+ return -1;
+ }
+
+ c->recv = NULL;
+ c->poll = NULL;
+ c->reapable = true;
+ return 0;
+}
+
+int utcp_abort(struct utcp_connection *c) {
+ if(!reset_connection(c)) {
+ return -1;
+ }
+
+ c->reapable = true;