tHandle curl_multi_socket_action errors - vaccinewars - be a doctor and try to vaccinate the world
 (HTM) git clone git://src.adamsgaard.dk/vaccinewars
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 0e22f437d27b6e6d722def9c12982dd6fbfd91d0
 (DIR) parent e952da0f48416fe7938267819aba65c53b41058c
 (HTM) Author: Ben Webb <ben@salilab.org>
       Date:   Thu,  5 Nov 2020 23:14:52 -0800
       
       Handle curl_multi_socket_action errors
       
       Provide a wrapper for curl_multi_socket_action that
       reports any errors using GError.
       
       Diffstat:
         M src/network.c                       |       8 ++++++++
         M src/network.h                       |       2 ++
         M src/serverside.c                    |      17 +++++++++++------
       
       3 files changed, 21 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/src/network.c b/src/network.c
       t@@ -1290,6 +1290,14 @@ gboolean CurlConnectionPerform(CurlConnection *conn, int *still_running,
          return HandleCurlMultiReturn(conn, mres, err);
        }
        
       +gboolean CurlConnectionSocketAction(CurlConnection *conn, int fd, int action,
       +                                    int *still_running, GError **err)
       +{
       +  CURLMcode mres = curl_multi_socket_action(conn->multi, fd, action,
       +                                            still_running);
       +  return HandleCurlMultiReturn(conn, mres, err);
       +}
       +
        GQuark dope_curl_error_quark(void)
        {
          return g_quark_from_static_string("dope-curl-error-quark");
 (DIR) diff --git a/src/network.h b/src/network.h
       t@@ -243,6 +243,8 @@ gboolean OpenCurlConnection(CurlConnection *conn, char *URL, char *body,
        void CloseCurlConnection(CurlConnection *conn);
        gboolean CurlConnectionPerform(CurlConnection *conn, int *still_running,
                                       GError **err);
       +gboolean CurlConnectionSocketAction(CurlConnection *conn, int fd, int action,
       +                                    int *still_running, GError **err);
        char *CurlNextLine(CurlConnection *conn, char *ch);
        void SetCurlCallback(CurlConnection *conn, GSourceFunc timer_cb,
                             GIOFunc socket_cb);
 (DIR) diff --git a/src/serverside.c b/src/serverside.c
       t@@ -1108,10 +1108,13 @@ static gboolean glib_timeout(gpointer userp)
        {
          CurlConnection *g = userp;
          int still_running;
       -  CURLMcode rc;
       +  GError *err = NULL;
          fprintf(stderr, "bw> glib_timeout\n");
       -  rc = curl_multi_socket_action(g->multi, CURL_SOCKET_TIMEOUT, 0, &still_running);
       -  if (rc != CURLM_OK) fprintf(stderr, "action %d %s\n", rc, curl_multi_strerror(rc));
       +  if (!CurlConnectionSocketAction(g, CURL_SOCKET_TIMEOUT, 0, &still_running,
       +                                  &err)) {
       +    MetaConnectError(g, err);
       +    g_error_free(err);
       +  }
          g->timer_event = 0;
          return G_SOURCE_REMOVE;
        }
       t@@ -1127,16 +1130,18 @@ static gboolean glib_socket(GIOChannel *ch, GIOCondition condition,
                                    gpointer data)
        {
          CurlConnection *g = (CurlConnection*) data;
       -  CURLMcode rc;
          int still_running;
       +  GError *err = NULL;
          int fd = g_io_channel_unix_get_fd(ch);
          fprintf(stderr, "bw> glib socket\n");
          int action =
            ((condition & G_IO_IN) ? CURL_CSELECT_IN : 0) |
            ((condition & G_IO_OUT) ? CURL_CSELECT_OUT : 0);
        
       -  rc = curl_multi_socket_action(g->multi, fd, action, &still_running);
       -  if (rc != CURLM_OK) fprintf(stderr, "action %d %s\n", rc, curl_multi_strerror(rc));
       +  if (!CurlConnectionSocketAction(g, fd, action, &still_running, &err)) {
       +    MetaConnectError(g, err);
       +    g_error_free(err);
       +  }
          if (still_running) {
            return TRUE;
          } else {