/[svn]/liblscp/trunk/src/client.c
ViewVC logotype

Diff of /liblscp/trunk/src/client.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3663 by schoenebeck, Sun Dec 22 12:41:28 2019 UTC revision 3842 by capela, Thu Dec 17 08:36:44 2020 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This library is free software; you can redistribute it and/or     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public     modify it under the terms of the GNU Lesser General Public
# Line 23  Line 23 
23  #include <locale.h>  #include <locale.h>
24  #include "common.h"  #include "common.h"
25  #include <sys/time.h>  #include <sys/time.h>
26    #ifdef WIN32
27    # include <errno.h>
28    #else
29    # include <sys/errno.h>
30    #endif
31    
32    
33  // Default timeout value (in milliseconds).  // Default timeout value (in milliseconds).
34  #define LSCP_TIMEOUT_MSECS  500  #define LSCP_TIMEOUT_MSECS  500
# Line 48  static lscp_status_t _lscp_client_evt_re Line 54  static lscp_status_t _lscp_client_evt_re
54  // General helper functions.  // General helper functions.
55    
56  struct _locale_t {  struct _locale_t {
57          char numeric[32];          char numeric[32+1];
58          char ctype[32];          char ctype[32+1];
59  };  };
60    
61  // we need to ensure a constant locale setting e.g. for parsing  // we need to ensure a constant locale setting e.g. for parsing
# Line 57  struct _locale_t { Line 63  struct _locale_t {
63  // character varies by the invidual locale settings  // character varies by the invidual locale settings
64  static void _save_and_set_c_locale(struct _locale_t* locale)  static void _save_and_set_c_locale(struct _locale_t* locale)
65  {  {
66            locale->numeric[32] = locale->ctype[32] = 0;
67          strncpy(locale->numeric, setlocale(LC_NUMERIC, NULL), 32);          strncpy(locale->numeric, setlocale(LC_NUMERIC, NULL), 32);
68          strncpy(locale->ctype, setlocale(LC_CTYPE, NULL), 32);          strncpy(locale->ctype, setlocale(LC_CTYPE, NULL), 32);
69          setlocale(LC_NUMERIC, "C");          setlocale(LC_NUMERIC, "C");
# Line 157  static void _lscp_client_evt_proc ( void Line 164  static void _lscp_client_evt_proc ( void
164                          } else {                          } else {
165                                  lscp_socket_perror("_lscp_client_evt_proc: recv");                                  lscp_socket_perror("_lscp_client_evt_proc: recv");
166                                  pClient->evt.iState = 0;                                  pClient->evt.iState = 0;
167                                    pClient->iErrno = -errno;
168                          }                          }
169                  }   // Check if select has in error.                  }   // Check if select has in error.
170                  else if (iSelect < 0) {                  else if (iSelect < 0) {
171                          lscp_socket_perror("_lscp_client_evt_proc: select");                          lscp_socket_perror("_lscp_client_evt_proc: select");
172                          pClient->evt.iState = 0;                          pClient->evt.iState = 0;
173                            pClient->iErrno = -errno;
174                  }                  }
175    
176                  // Finally, always signal the event.                  // Finally, always signal the event.
# Line 639  int lscp_client_get_timeout ( lscp_clien Line 648  int lscp_client_get_timeout ( lscp_clien
648          return pClient->iTimeout;          return pClient->iTimeout;
649  }  }
650    
651    /**
652     *  Check whether connection to server is lost.
653     *
654     *  @param pClient  Pointer to client instance structure.
655     *
656     *  @returns @c true if client lost connection to server, @c false otherwise.
657     */
658    bool lscp_client_connection_lost ( lscp_client_t *pClient )
659    {
660        int err = lscp_client_get_errno(pClient);
661        if (err >= 0) return false;
662        return err == -EPIPE || err == -ECONNRESET || err == -ECONNABORTED;
663    }
664    
665    
666  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
667  // Client common protocol functions.  // Client common protocol functions.

Legend:
Removed from v.3663  
changed lines
  Added in v.3842

  ViewVC Help
Powered by ViewVC