]> git.meshlink.io Git - meshlink/blobdiff - src/protocol_misc.c
Avoid allocating packet buffers unnecessarily.
[meshlink] / src / protocol_misc.c
index d0401b93be299bddd5e232fda3f3bf6688ee6d58..c6a3630ae2ea190fc27ee41dbe8b9206c85591b9 100644 (file)
@@ -34,6 +34,9 @@ int maxoutbufsize = 0;
 /* Status and error notification routines */
 
 bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        int statusno;
        char statusstring[MAX_STRING_SIZE];
 
@@ -48,6 +51,9 @@ bool status_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 }
 
 bool error_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        int err;
        char errorstring[MAX_STRING_SIZE];
 
@@ -65,6 +71,10 @@ bool termreq_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        (void)mesh;
        (void)c;
        (void)request;
+
+       assert(request);
+       assert(*request);
+
        return false;
 }
 
@@ -77,6 +87,10 @@ bool send_ping(meshlink_handle_t *mesh, connection_t *c) {
 
 bool ping_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        (void)request;
+
+       assert(request);
+       assert(*request);
+
        return send_pong(mesh, c);
 }
 
@@ -87,20 +101,16 @@ bool send_pong(meshlink_handle_t *mesh, connection_t *c) {
 bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
        (void)mesh;
        (void)request;
-       c->status.pinged = false;
 
-       /* Succesful connection, reset timeout if this is an outgoing connection. */
+       assert(request);
+       assert(*request);
 
-       if(c->outgoing) {
-               c->outgoing->timeout = 0;
-               c->outgoing->cfg = NULL;
+       c->status.pinged = false;
 
-               if(c->outgoing->ai) {
-                       freeaddrinfo(c->outgoing->ai);
-               }
+       /* Successful connection, reset timeout if this is an outgoing connection. */
 
-               c->outgoing->ai = NULL;
-               c->outgoing->aip = NULL;
+       if(c->outgoing) {
+               reset_outgoing(c->outgoing);
        }
 
        return true;
@@ -109,6 +119,9 @@ bool pong_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
 /* Sending and receiving packets via TCP */
 
 bool tcppacket_h(meshlink_handle_t *mesh, connection_t *c, const char *request) {
+       assert(request);
+       assert(*request);
+
        short int len;
 
        if(sscanf(request, "%*d %hd", &len) != 1) {