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

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

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

revision 378 by capela, Sun Feb 13 17:20:46 2005 UTC revision 623 by capela, Thu Jun 9 10:37:19 2005 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     liblscp - LinuxSampler Control Protocol API     liblscp - LinuxSampler Control Protocol API
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2005, 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 133  lscp_status_t lscp_client_call ( lscp_cl Line 133  lscp_status_t lscp_client_call ( lscp_cl
133          return ret;          return ret;
134      }      }
135    
136            // Check if last transaction has timed out, in which case
137            // we'll retry wait and flush for some pending garbage...
138            if (pClient->iTimeoutCount > 0) {
139                    cchResult = sizeof(achResult);
140                    ret = lscp_client_recv(pClient, achResult, &cchResult, pClient->iTimeout);
141                    if (ret == LSCP_OK) {
142                            // We've got rid of timeout trouble (hopefully).
143                            pClient->iTimeoutCount = 0;
144                    } else {
145                            // Things are worse than before. Fake a result message.
146                            iErrno = (int) ret;
147                            pszResult = "Failure during flush timeout operation";
148                            lscp_client_set_result(pClient, pszResult, iErrno);
149                            return ret;
150                    }
151            }
152    
153      // Send data, and then, wait for the result...      // Send data, and then, wait for the result...
154      cchQuery = strlen(pszQuery);      cchQuery = strlen(pszQuery);
155      if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {      if (send(pClient->cmd.sock, pszQuery, cchQuery, 0) < cchQuery) {
# Line 188  lscp_status_t lscp_client_call ( lscp_cl Line 205  lscp_status_t lscp_client_call ( lscp_cl
205          break;          break;
206    
207        case LSCP_TIMEOUT:        case LSCP_TIMEOUT:
208                    // We have trouble...
209            pClient->iTimeoutCount++;
210          // Fake a result message.          // Fake a result message.
211          pszResult = "Timeout during receive operation";          pszResult = "Timeout during receive operation";
212          iErrno = (int) ret;          iErrno = (int) ret;
# Line 329  char **lscp_szsplit_create ( const char Line 348  char **lscp_szsplit_create ( const char
348              --pch;              --pch;
349          *pch = (char) 0;          *pch = (char) 0;
350          // Make it official.          // Make it official.
351          ppszSplit[i++] = lscp_unquote(&pszHead, 0);          ppszSplit[i] = lscp_unquote(&pszHead, 0);
352          // Do we need to grow?          // Do we need to grow?
353          if (i >= iSize) {          if (++i >= iSize) {
354              // Yes, but only grow in chunks.              // Yes, but only grow in chunks.
355              iSize += LSCP_SPLIT_CHUNK1;              iSize += LSCP_SPLIT_CHUNK1;
356              // Allocate and copy to new split array.              // Allocate and copy to new split array.
# Line 396  int *lscp_isplit_create ( const char *ps Line 415  int *lscp_isplit_create ( const char *ps
415      pchHead = lscp_ltrim((char *) pszCsv);      pchHead = lscp_ltrim((char *) pszCsv);
416      if (*pchHead == (char) 0)      if (*pchHead == (char) 0)
417          return NULL;          return NULL;
418        
419      // Initial size is one chunk away.      // Initial size is one chunk away.
420      iSize = LSCP_SPLIT_CHUNK1;      iSize = LSCP_SPLIT_CHUNK1;
421      // Allocate and split...      // Allocate and split...
# Line 417  int *lscp_isplit_create ( const char *ps Line 436  int *lscp_isplit_create ( const char *ps
436          // Pre-advance to next item.          // Pre-advance to next item.
437          pchHead = pch + cchSeps;          pchHead = pch + cchSeps;
438          // Make it official.          // Make it official.
439          piSplit[i++] = atoi(pchHead);          piSplit[i] = atoi(pchHead);
440          // Do we need to grow?          // Do we need to grow?
441          if (i >= iSize) {          if (++i >= iSize) {
442              // Yes, but only grow in chunks.              // Yes, but only grow in chunks.
443              iSize += LSCP_SPLIT_CHUNK1;              iSize += LSCP_SPLIT_CHUNK1;
444              // Allocate and copy to new split array.              // Allocate and copy to new split array.
# Line 581  void lscp_plist_free ( lscp_param_t **pp Line 600  void lscp_plist_free ( lscp_param_t **pp
600  {  {
601      lscp_param_t *pParams;      lscp_param_t *pParams;
602      int i;      int i;
603        
604      if (ppList) {      if (ppList) {
605          if (*ppList) {          if (*ppList) {
606              pParams = *ppList;              pParams = *ppList;
# Line 603  void lscp_plist_append ( lscp_param_t ** Line 622  void lscp_plist_append ( lscp_param_t **
622      lscp_param_t *pNewParams;      lscp_param_t *pNewParams;
623      int iSize, iNewSize;      int iSize, iNewSize;
624      int i = 0;      int i = 0;
625        
626      if (ppList && *ppList) {      if (ppList && *ppList) {
627          pParams = *ppList;          pParams = *ppList;
628          while (pParams[i].key) {          while (pParams[i].key) {
# Line 622  void lscp_plist_append ( lscp_param_t ** Line 641  void lscp_plist_append ( lscp_param_t **
641              iNewSize   = iSize + LSCP_SPLIT_CHUNK1;              iNewSize   = iSize + LSCP_SPLIT_CHUNK1;
642              pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t));              pNewParams = (lscp_param_t *) malloc(iNewSize * sizeof(lscp_param_t));
643              for (i = 0; i < iSize; i++) {              for (i = 0; i < iSize; i++) {
644                  pParams[i].key   = pParams[i].key;                  pNewParams[i].key   = pParams[i].key;
645                  pParams[i].value = pParams[i].value;                  pNewParams[i].value = pParams[i].value;
646              }              }
647              for ( ; i < iNewSize; i++) {              for ( ; i < iNewSize; i++) {
648                  pNewParams[i].key   = NULL;                  pNewParams[i].key   = NULL;
# Line 660  int lscp_plist_size ( lscp_param_t **ppL Line 679  int lscp_plist_size ( lscp_param_t **ppL
679    
680    
681  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
682    // Server info struct helper functions.
683    
684    void lscp_server_info_init ( lscp_server_info_t *pServerInfo )
685    {
686        pServerInfo->description = NULL;
687        pServerInfo->version     = NULL;
688    }
689    
690    void lscp_server_info_free ( lscp_server_info_t *pServerInfo )
691    {
692        if (pServerInfo->description)
693            free(pServerInfo->description);
694        if (pServerInfo->version)
695            free(pServerInfo->version);
696    }
697    
698    void lscp_server_info_reset ( lscp_server_info_t *pServerInfo )
699    {
700        lscp_server_info_free(pServerInfo);
701        lscp_server_info_init(pServerInfo);
702    }
703    
704    
705    //-------------------------------------------------------------------------
706  // Engine info struct helper functions.  // Engine info struct helper functions.
707    
708  void lscp_engine_info_init ( lscp_engine_info_t *pEngineInfo )  void lscp_engine_info_init ( lscp_engine_info_t *pEngineInfo )

Legend:
Removed from v.378  
changed lines
  Added in v.623

  ViewVC Help
Powered by ViewVC