您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ Curl_tvdiff函数代码示例

51自学网 2021-06-01 20:16:18
  C++
这篇教程C++ Curl_tvdiff函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中Curl_tvdiff函数的典型用法代码示例。如果您正苦于以下问题:C++ Curl_tvdiff函数的具体用法?C++ Curl_tvdiff怎么用?C++ Curl_tvdiff使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Curl_tvdiff函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: Curl_pp_state_timeout

/* Returns timeout in ms. 0 or negative number means the timeout has already   triggered */long Curl_pp_state_timeout(struct pingpong *pp){  struct connectdata *conn = pp->conn;  struct Curl_easy *data=conn->data;  long timeout_ms; /* in milliseconds */  long timeout2_ms; /* in milliseconds */  long response_time= (data->set.server_response_timeout)?    data->set.server_response_timeout: pp->response_time;  /* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine     remaining time, or use pp->response because SERVER_RESPONSE_TIMEOUT is     supposed to govern the response for any given server response, not for     the time from connect to the given server response. */  /* Without a requested timeout, we only wait 'response_time' seconds for the     full response to arrive before we bail out */  timeout_ms = response_time -    Curl_tvdiff(Curl_tvnow(), pp->response); /* spent time */  if(data->set.timeout) {    /* if timeout is requested, find out how much remaining time we have */    timeout2_ms = data->set.timeout - /* timeout time */      Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */    /* pick the lowest number */    timeout_ms = CURLMIN(timeout_ms, timeout2_ms);  }  return timeout_ms;}
开发者ID:2px,项目名称:curl,代码行数:32,


示例2: Curl_pp_state_timeout

/* Returns timeout in ms. 0 or negative number means the timeout has already   triggered */long Curl_pp_state_timeout(struct pingpong *pp){  struct connectdata *conn = pp->conn;  struct SessionHandle *data=conn->data;  long timeout_ms=360000; /* in milliseconds */  if(data->set.server_response_timeout )    /* if CURLOPT_SERVER_RESPONSE_TIMEOUT is set, use that to determine       remaining time.  Also, use pp->response because SERVER_RESPONSE_TIMEOUT       is supposed to govern the response for any given server response, not       for the time from connect to the given server response. */    timeout_ms = data->set.server_response_timeout - /* timeout time */      Curl_tvdiff(Curl_tvnow(), pp->response); /* spent time */  else if(data->set.timeout)    /* if timeout is requested, find out how much remaining time we have */    timeout_ms = data->set.timeout - /* timeout time */      Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */  else    /* Without a requested timeout, we only wait 'response_time' seconds for       the full response to arrive before we bail out */    timeout_ms = pp->response_time -      Curl_tvdiff(Curl_tvnow(), pp->response); /* spent time */  return timeout_ms;}
开发者ID:bagobor,项目名称:vs-curl-test,代码行数:27,


示例3: Curl_timeleft

/* * Curl_timeleft() returns the amount of milliseconds left allowed for the * transfer/connection. If the value is negative, the timeout time has already * elapsed. * * The start time is stored in progress.t_startsingle - as set with * Curl_pgrsTime(..., TIMER_STARTSINGLE); * * If 'nowp' is non-NULL, it points to the current time. * 'duringconnect' is FALSE if not during a connect, as then of course the * connect timeout is not taken into account! * * @unittest: 1303 */long Curl_timeleft(struct SessionHandle *data,                   struct timeval *nowp,                   bool duringconnect){  int timeout_set = 0;  long timeout_ms = duringconnect?DEFAULT_CONNECT_TIMEOUT:0;  struct timeval now;  /* if a timeout is set, use the most restrictive one */  if(data->set.timeout > 0)    timeout_set |= 1;  if(duringconnect && (data->set.connecttimeout > 0))    timeout_set |= 2;  switch (timeout_set) {  case 1:    timeout_ms = data->set.timeout;    break;  case 2:    timeout_ms = data->set.connecttimeout;    break;  case 3:    if(data->set.timeout < data->set.connecttimeout)      timeout_ms = data->set.timeout;    else      timeout_ms = data->set.connecttimeout;    break;  default:    /* use the default */    if(!duringconnect)      /* if we're not during connect, there's no default timeout so if we're         at zero we better just return zero and not make it a negative number         by the math below */      return 0;    break;  }  if(!nowp) {    now = Curl_tvnow();    nowp = &now;  }  /* subtract elapsed time */  if(duringconnect)    /* since this most recent connect started */    timeout_ms -= Curl_tvdiff(*nowp, data->progress.t_startsingle);  else    /* since the entire operation started */    timeout_ms -= Curl_tvdiff(*nowp, data->progress.t_startop);  if(!timeout_ms)    /* avoid returning 0 as that means no timeout! */    return -1;  return timeout_ms;}
开发者ID:BishopGIS,项目名称:cmake4libs,代码行数:70,


示例4: Curl_speedcheck

CURLcode Curl_speedcheck(struct SessionHandle *data,                         struct timeval now){  if((data->progress.current_speed >= 0) &&     data->set.low_speed_time &&     (Curl_tvlong(data->state.keeps_speed) != 0) &&     (data->progress.current_speed < data->set.low_speed_limit)) {    long howlong = Curl_tvdiff(now, data->state.keeps_speed);    /* We are now below the "low speed limit". If we are below it       for "low speed time" seconds we consider that enough reason       to abort the download. */    if( (howlong/1000) > data->set.low_speed_time) {      /* we have been this slow for long enough, now die */      failf(data,            "Operation too slow. "            "Less than %d bytes/sec transfered the last %d seconds",            data->set.low_speed_limit,            data->set.low_speed_time);      return CURLE_OPERATION_TIMEOUTED;    }    Curl_expire(data, howlong);  }  else {    /* we keep up the required speed all right */    data->state.keeps_speed = now;  }  return CURLE_OK;}
开发者ID:thenfour,项目名称:screenie,代码行数:30,


示例5: Curl_is_resolved

/* * Curl_is_resolved() is called repeatedly to check if a previous name resolve * request has completed. It should also make sure to time-out if the * operation seems to take too long. */CURLcode Curl_is_resolved(struct connectdata *conn,                          struct Curl_dns_entry **entry){  struct SessionHandle *data = conn->data;  struct thread_data   *td = (struct thread_data*) conn->async.os_specific;  int done = 0;   *entry = NULL;  if (!td) {    DEBUGASSERT(td);    return CURLE_COULDNT_RESOLVE_HOST;  }  Curl_mutex_acquire(td->tsd.mtx);  done = td->tsd.done;  Curl_mutex_release(td->tsd.mtx);  if (done) {     getaddrinfo_complete(conn);    if (td->poll_interval != 0)        Curl_expire(conn->data, 0);    Curl_destroy_thread_data(&conn->async);    if(!conn->async.dns) {      failf(data, "Could not resolve host: %s; %s",            conn->host.name, Curl_strerror(conn, conn->async.status));      return CURLE_COULDNT_RESOLVE_HOST;    }    *entry = conn->async.dns;  } else {    /* poll for name lookup done with exponential backoff up to 250ms */    int elapsed;    elapsed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);    if (elapsed < 0) {      elapsed = 0;    }    if (td->poll_interval == 0) {      /* Start at 1ms poll interval */      td->poll_interval = 1;    } else if (elapsed >= td->interval_end) {      /* Back-off exponentially if last interval expired  */      td->poll_interval *= 2;    }    if (td->poll_interval > 250)      td->poll_interval = 250;    td->interval_end = elapsed + td->poll_interval;    Curl_expire(conn->data, td->poll_interval);  }  return CURLE_OK;}
开发者ID:bagobor,项目名称:vs-curl-test,代码行数:62,


示例6: Curl_blockread_all

/* * Helper read-from-socket functions. Does the same as Curl_read() but it * blocks until all bytes amount of buffersize will be read. No more, no less. * * This is STUPID BLOCKING behaviour which we frown upon, but right now this * is what we have... */int Curl_blockread_all(struct connectdata *conn, /* connection data */                       curl_socket_t sockfd,     /* read from this socket */                       char *buf,                /* store read data here */                       ssize_t buffersize,       /* max amount to read */                       ssize_t *n,               /* amount bytes read */                       long conn_timeout)        /* timeout for data wait                                                    relative to                                                    conn->created */{  ssize_t nread;  ssize_t allread = 0;  int result;  struct timeval tvnow;  long conntime;  *n = 0;  for(;;) {    tvnow = Curl_tvnow();    /* calculating how long connection is establishing */    conntime = Curl_tvdiff(tvnow, conn->created);    if(conntime > conn_timeout) {      /* we already got the timeout */      result = CURLE_OPERATION_TIMEDOUT;      break;    }    if(Curl_socket_ready(sockfd, CURL_SOCKET_BAD,                   (int)(conn_timeout - conntime)) <= 0) {      result = ~CURLE_OK;      break;    }    result = Curl_read_plain(sockfd, buf, buffersize, &nread);    if(CURLE_AGAIN == result)      continue;    else if(result)      break;    if(buffersize == nread) {      allread += nread;      *n = allread;      result = CURLE_OK;      break;    }    if(!nread) {      result = ~CURLE_OK;      break;    }    buffersize -= nread;    buf += nread;    allread += nread;  }  return result;}
开发者ID:1833183060,项目名称:wke,代码行数:59,


示例7: Curl_resolver_is_resolved

/* * Curl_resolver_is_resolved() is called repeatedly to check if a previous * name resolve request has completed. It should also make sure to time-out if * the operation seems to take too long. */CURLcode Curl_resolver_is_resolved(struct connectdata *conn,                                   struct Curl_dns_entry **entry){  struct Curl_easy *data = conn->data;  struct thread_data   *td = (struct thread_data*) conn->async.os_specific;  int done = 0;  *entry = NULL;  if(!td) {    DEBUGASSERT(td);    return CURLE_COULDNT_RESOLVE_HOST;  }  Curl_mutex_acquire(td->tsd.mtx);  done = td->tsd.done;  Curl_mutex_release(td->tsd.mtx);  if(done) {    getaddrinfo_complete(conn);    if(!conn->async.dns) {      CURLcode result = resolver_error(conn);      destroy_async_data(&conn->async);      return result;    }    destroy_async_data(&conn->async);    *entry = conn->async.dns;  }  else {    /* poll for name lookup done with exponential backoff up to 250ms */    long elapsed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);    if(elapsed < 0)      elapsed = 0;    if(td->poll_interval == 0)      /* Start at 1ms poll interval */      td->poll_interval = 1;    else if(elapsed >= td->interval_end)      /* Back-off exponentially if last interval expired  */      td->poll_interval *= 2;    if(td->poll_interval > 250)      td->poll_interval = 250;    td->interval_end = elapsed + td->poll_interval;    Curl_expire(conn->data, td->poll_interval);  }  return CURLE_OK;}
开发者ID:2px,项目名称:curl,代码行数:56,


示例8: Curl_speedcheck

CURLcode Curl_speedcheck(struct Curl_easy *data,                         struct timeval now){  if((data->progress.current_speed >= 0) &&     data->set.low_speed_time &&     (Curl_tvlong(data->state.keeps_speed) != 0) &&     (data->progress.current_speed < data->set.low_speed_limit)) {    long howlong = Curl_tvdiff(now, data->state.keeps_speed);    long nextcheck = (data->set.low_speed_time * 1000) - howlong;    /* We are now below the "low speed limit". If we are below it       for "low speed time" seconds we consider that enough reason       to abort the download. */    if(nextcheck <= 0) {      /* we have been this slow for long enough, now die */      failf(data,            "Operation too slow. "            "Less than %ld bytes/sec transferred the last %ld seconds",            data->set.low_speed_limit,            data->set.low_speed_time);      return CURLE_OPERATION_TIMEDOUT;    }    else {      /* wait complete low_speed_time */      Curl_expire_latest(data, nextcheck);    }  }  else {    /* we keep up the required speed all right */    data->state.keeps_speed = now;    if(data->set.low_speed_limit)      /* if there is a low speed limit enabled, we set the expire timer to         make this connection's speed get checked again no later than when         this time is up */      Curl_expire_latest(data, data->set.low_speed_time*1000);  }  return CURLE_OK;}
开发者ID:2px,项目名称:curl,代码行数:39,


示例9: Curl_resolv_timeout

//.........这里部分代码省略.........  /*************************************************************   * Set signal handler to catch SIGALRM   * Store the old value to be able to set it back later!   *************************************************************/#ifdef HAVE_SIGACTION  sigaction(SIGALRM, NULL, &sigact);  keep_sigact = sigact;  keep_copysig = TRUE; /* yes, we have a copy */  sigact.sa_handler = alarmfunc;#ifdef SA_RESTART  /* HPUX doesn't have SA_RESTART but defaults to that behaviour! */  sigact.sa_flags &= ~SA_RESTART;#endif  /* now set the new struct */  sigaction(SIGALRM, &sigact, NULL);#else /* HAVE_SIGACTION */  /* no sigaction(), revert to the much lamer signal() */#ifdef HAVE_SIGNAL  keep_sigact = signal(SIGALRM, alarmfunc);#endif#endif /* HAVE_SIGACTION */  /* alarm() makes a signal get sent when the timeout fires off, and that     will abort system calls */  prev_alarm = alarm(curlx_sltoui(timeout/1000L));  /* This allows us to time-out from the name resolver, as the timeout     will generate a signal and we will siglongjmp() from that here.     This technique has problems (see alarmfunc).     This should be the last thing we do before calling Curl_resolv(),     as otherwise we'd have to worry about variables that get modified     before we invoke Curl_resolv() (and thus use "volatile"). */  if(sigsetjmp(curl_jmpenv, 1)) {    /* this is coming from a siglongjmp() after an alarm signal */    failf(data, "name lookup timed out");    rc = CURLRESOLV_ERROR;    goto clean_up;  }#else#ifndef CURLRES_ASYNCH  if(timeoutms)    infof(conn->data, "timeout on name lookup is not supported/n");#else  (void)timeoutms; /* timeoutms not used with an async resolver */#endif#endif /* USE_ALARM_TIMEOUT */  /* Perform the actual name resolution. This might be interrupted by an   * alarm if it takes too long.   */  rc = Curl_resolv(conn, hostname, port, entry);#ifdef USE_ALARM_TIMEOUTclean_up:  if(!prev_alarm)    /* deactivate a possibly active alarm before uninstalling the handler */    alarm(0);#ifdef HAVE_SIGACTION  if(keep_copysig) {    /* we got a struct as it looked before, now put that one back nice       and clean */    sigaction(SIGALRM, &keep_sigact, NULL); /* put it back */  }#else#ifdef HAVE_SIGNAL  /* restore the previous SIGALRM handler */  signal(SIGALRM, keep_sigact);#endif#endif /* HAVE_SIGACTION */  /* switch back the alarm() to either zero or to what it was before minus     the time we spent until now! */  if(prev_alarm) {    /* there was an alarm() set before us, now put it back */    unsigned long elapsed_ms = Curl_tvdiff(Curl_tvnow(), conn->created);    /* the alarm period is counted in even number of seconds */    unsigned long alarm_set = prev_alarm - elapsed_ms/1000;    if(!alarm_set ||       ((alarm_set >= 0x80000000) && (prev_alarm < 0x80000000)) ) {      /* if the alarm time-left reached zero or turned "negative" (counted         with unsigned values), we should fire off a SIGALRM here, but we         won't, and zero would be to switch it off so we never set it to         less than 1! */      alarm(1);      rc = CURLRESOLV_TIMEDOUT;      failf(data, "Previous alarm fired off!");    }    else      alarm((unsigned int)alarm_set);  }#endif /* USE_ALARM_TIMEOUT */  return rc;}
开发者ID:1007650105,项目名称:aseprite,代码行数:101,


示例10: Curl_resolver_wait_resolv

/* * Curl_resolver_wait_resolv() * * waits for a resolve to finish. This function should be avoided since using * this risk getting the multi interface to "hang". * * If 'entry' is non-NULL, make it point to the resolved dns entry * * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and * CURLE_OPERATION_TIMEDOUT if a time-out occurred. */CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,                                   struct Curl_dns_entry **entry){  CURLcode result = CURLE_OK;  struct Curl_easy *data = conn->data;  long timeout;  struct timeval now = Curl_tvnow();  struct Curl_dns_entry *temp_entry;  if(entry)    *entry = NULL; /* clear on entry */  timeout = Curl_timeleft(data, &now, TRUE);  if(timeout < 0) {    /* already expired! */    connclose(conn, "Timed out before name resolve started");    return CURLE_OPERATION_TIMEDOUT;  }  if(!timeout)    timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */  /* Wait for the name resolve query to complete. */  while(!result) {    struct timeval *tvp, tv, store;    long timediff;    int itimeout;    int timeout_ms;    itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;    store.tv_sec = itimeout/1000;    store.tv_usec = (itimeout%1000)*1000;    tvp = ares_timeout((ares_channel)data->state.resolver, &store, &tv);    /* use the timeout period ares returned to us above if less than one       second is left, otherwise just use 1000ms to make sure the progress       callback gets called frequent enough */    if(!tvp->tv_sec)      timeout_ms = (int)(tvp->tv_usec/1000);    else      timeout_ms = 1000;    waitperform(conn, timeout_ms);    result = Curl_resolver_is_resolved(conn, &temp_entry);    if(result || conn->async.done)      break;    if(Curl_pgrsUpdate(conn))      result = CURLE_ABORTED_BY_CALLBACK;    else {      struct timeval now2 = Curl_tvnow();      timediff = Curl_tvdiff(now2, now); /* spent time */      timeout -= timediff?timediff:1; /* always deduct at least 1 */      now = now2; /* for next loop */    }    if(timeout < 0)      result = CURLE_OPERATION_TIMEDOUT;  }  if(result)    /* failure, so we cancel the ares operation */    ares_cancel((ares_channel)data->state.resolver);  /* Operation complete, if the lookup was successful we now have the entry     in the cache. */  if(entry)    *entry = conn->async.dns;  if(result)    /* close the connection, since we can't return failure here without       cleaning up this connection properly.       TODO: remove this action from here, it is not a name resolver decision.    */    connclose(conn, "c-ares resolve failed");  return result;}
开发者ID:FunTW,项目名称:terminal,代码行数:89,


示例11: Curl_is_connected

CURLcode Curl_is_connected(struct connectdata *conn,                           curl_socket_t sockfd,                           bool *connected){  int rc;  struct SessionHandle *data = conn->data;  *connected = FALSE; /* a very negative world view is best */  if(data->set.timeout || data->set.connecttimeout) {    /* there is a timeout set */    /* Evaluate in milliseconds how much time that has passed */    long has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.start);    /* subtract the most strict timeout of the ones */    if(data->set.timeout && data->set.connecttimeout) {      if (data->set.timeout < data->set.connecttimeout)        has_passed -= data->set.timeout*1000;      else         has_passed -= data->set.connecttimeout*1000;    }    else if(data->set.timeout)      has_passed -= data->set.timeout*1000;    else      has_passed -= data->set.connecttimeout*1000;    if(has_passed > 0 ) {      /* time-out, bail out, go home */      failf(data, "Connection time-out");      return CURLE_OPERATION_TIMEOUTED;    }  }  if(conn->bits.tcpconnect) {    /* we are connected already! */    *connected = TRUE;    return CURLE_OK;  }  /* check for connect without timeout as we want to return immediately */  rc = waitconnect(sockfd, 0);  if(0 == rc) {    if (verifyconnect(sockfd)) {      /* we are connected, awesome! */      *connected = TRUE;      return CURLE_OK;    }    /* nope, not connected for real */    failf(data, "Connection failed");    return CURLE_COULDNT_CONNECT;  }  else if(1 != rc) {    int error = Curl_ourerrno();    failf(data, "Failed connect to %s:%d, errno: %d",          conn->hostname, conn->port, error);    return CURLE_COULDNT_CONNECT;  }  /*   * If the connection phase is "done" here, we should attempt to connect   * to the "next address" in the Curl_hostaddr structure that we resolved   * before. But we don't have that struct around anymore and we can't just   * keep a pointer since the cache might in fact have gotten pruned by the   * time we want to read this... Alas, we don't do this yet.   */  return CURLE_OK;}
开发者ID:0culus,项目名称:Doom3-for-MacOSX-,代码行数:68,


示例12: Curl_wait_for_resolv

/* This is a function that locks and waits until the name resolve operation   has completed.   If 'entry' is non-NULL, make it point to the resolved dns entry   Return CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and   CURLE_OPERATION_TIMEDOUT if a time-out occurred.*/CURLcode Curl_wait_for_resolv(struct connectdata *conn,                              struct Curl_dns_entry **entry){  CURLcode rc=CURLE_OK;  struct SessionHandle *data = conn->data;  struct timeval now = Curl_tvnow();  bool timedout = FALSE;  long timeout = 300; /* default name resolve timeout in seconds */  long elapsed = 0; /* time taken so far */  /* now, see if there's a connect timeout or a regular timeout to     use instead of the default one */  if(conn->data->set.connecttimeout)    timeout = conn->data->set.connecttimeout;  else if(conn->data->set.timeout)    timeout = conn->data->set.timeout;  /* Wait for the name resolve query to complete. */  while (1) {    int nfds=0;    fd_set read_fds, write_fds;    struct timeval *tvp, tv, store;    int count;    store.tv_sec = (int)(timeout - elapsed);    store.tv_usec = 0;        FD_ZERO(&read_fds);    FD_ZERO(&write_fds);    nfds = ares_fds(data->state.areschannel, &read_fds, &write_fds);    if (nfds == 0)      break;    tvp = ares_timeout(data->state.areschannel,                       &store, &tv);    count = select(nfds, &read_fds, &write_fds, NULL, tvp);    if (count < 0 && errno != EINVAL)      break;    else if(!count) {      /* timeout */      timedout = TRUE;      break;    }    ares_process(data->state.areschannel, &read_fds, &write_fds);    elapsed = Curl_tvdiff(Curl_tvnow(), now)/1000; /* spent time */  }  /* Operation complete, if the lookup was successful we now have the entry     in the cache. */      if(entry)    *entry = conn->async.dns;  if(!conn->async.dns) {    /* a name was not resolved */    if(timedout || (conn->async.status == ARES_ETIMEOUT)) {      failf(data, "Resolving host timed out: %s", conn->name);      rc = CURLE_OPERATION_TIMEDOUT;    }    else if(conn->async.done) {      failf(data, "Could not resolve host: %s (%s)", conn->name,            ares_strerror(conn->async.status));      rc = CURLE_COULDNT_RESOLVE_HOST;    }    else      rc = CURLE_OPERATION_TIMEDOUT;    /* close the connection, since we can't return failure here without       cleaning up this connection properly */    Curl_disconnect(conn);  }    return rc;}
开发者ID:tankorsmash,项目名称:quadcow,代码行数:82,


示例13: Curl_telnet

//.........这里部分代码省略.........          if(tn->please_negotiate && !tn->already_negotiated) {            negotiate(conn);            tn->already_negotiated = 1;          }        }        if(events.lNetworkEvents & FD_CLOSE) {          keepon = FALSE;        }      }      break;    }  }  /* We called WSACreateEvent, so call WSACloseEvent */  if (close_event_func(event_handle) == FALSE) {    infof(data,"WSACloseEvent failed (%d)", SOCKERRNO);  }  /* "Forget" pointers into the library we're about to free */  create_event_func = NULL;  close_event_func = NULL;  event_select_func = NULL;  enum_netevents_func = NULL;  /* We called LoadLibrary, so call FreeLibrary */  if (!FreeLibrary(wsock2))    infof(data,"FreeLibrary(wsock2) failed (%d)", ERRNO);#else  pfd[0].fd = sockfd;  pfd[0].events = POLLIN;  pfd[1].fd = 0;  pfd[1].events = POLLIN;  interval_ms = 1 * 1000;  while (keepon) {    switch (Curl_poll(pfd, 2, interval_ms)) {    case -1:                    /* error, stop reading */      keepon = FALSE;      continue;    case 0:                     /* timeout */      break;    default:                    /* read! */      if(pfd[1].revents & POLLIN) { /* read from stdin */        unsigned char outbuf[2];        int out_count = 0;        ssize_t bytes_written;        char *buffer = buf;        nread = read(0, buf, 255);        while(nread--) {          outbuf[0] = *buffer++;          out_count = 1;          if(outbuf[0] == CURL_IAC)            outbuf[out_count++] = CURL_IAC;          Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf,                     out_count, &bytes_written);        }      }      if(pfd[0].revents & POLLIN) {        /* This OUGHT to check the return code... */        (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);        /* if we receive 0 or less here, the server closed the connection and           we bail out from this! */        if (nread <= 0) {          keepon = FALSE;          break;        }        telrcv(conn, (unsigned char *)buf, nread);        /* Negotiate if the peer has started negotiating,           otherwise don't. We don't want to speak telnet with           non-telnet servers, like POP or SMTP. */        if(tn->please_negotiate && !tn->already_negotiated) {          negotiate(conn);          tn->already_negotiated = 1;        }      }    }    if(data->set.timeout) {      struct timeval now;           /* current time */      now = Curl_tvnow();      if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {        failf(data, "Time-out");        code = CURLE_OPERATION_TIMEDOUT;        keepon = FALSE;      }    }  }#endif  /* mark this as "no further transfer wanted" */  Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);  return code;}
开发者ID:irmametra,项目名称:EiffelStudio,代码行数:101,


示例14: Curl_ConnectHTTPProxyTunnel

CURLcode Curl_ConnectHTTPProxyTunnel(struct connectdata *conn,                                     int tunnelsocket,                                     char *hostname, int remote_port){  int httperror=0;  int subversion=0;  struct SessionHandle *data=conn->data;  CURLcode result;  int res;  int nread;   /* total size read */  int perline; /* count bytes per line */  bool keepon=TRUE;  ssize_t gotbytes;  char *ptr;  int timeout = 3600; /* default timeout in seconds */  struct timeval interval;  fd_set rkeepfd;  fd_set readfd;  char *line_start;#define SELECT_OK      0#define SELECT_ERROR   1#define SELECT_TIMEOUT 2  int error = SELECT_OK;  infof(data, "Establish HTTP proxy tunnel to %s:%d/n", hostname, remote_port);  /* OK, now send the connect request to the proxy */  result =    Curl_sendf(tunnelsocket, conn,               "CONNECT %s:%d HTTP/1.0/015/012"               "%s"               "%s"               "/r/n",               hostname, remote_port,               (conn->bits.proxy_user_passwd)?conn->allocptr.proxyuserpwd:"",               (data->set.useragent?conn->allocptr.uagent:"")               );  if(result) {    failf(data, "Failed sending CONNECT to proxy");    return result;  }  /* Now, read the full reply we get from the proxy */  if(data->set.timeout) {    /* if timeout is requested, find out how much remaining time we have */    timeout = data->set.timeout - /* timeout time */      Curl_tvdiff(Curl_tvnow(), conn->now)/1000; /* spent time */    if(timeout <=0 ) {      failf(data, "Transfer aborted due to timeout");      return -SELECT_TIMEOUT; /* already too little time */    }  }  FD_ZERO (&readfd);		/* clear it */  FD_SET (tunnelsocket, &readfd);     /* read socket */  /* get this in a backup variable to be able to restore it on each lap in the     select() loop */  rkeepfd = readfd;  ptr=data->state.buffer;  line_start = ptr;  nread=0;  perline=0;  keepon=TRUE;  while((nread<BUFSIZE) && (keepon && !error)) {    readfd = rkeepfd;		   /* set every lap */    interval.tv_sec = timeout;    interval.tv_usec = 0;    switch (select (tunnelsocket+1, &readfd, NULL, NULL, &interval)) {    case -1: /* select() error, stop reading */      error = SELECT_ERROR;      failf(data, "Transfer aborted due to select() error");      break;    case 0: /* timeout */      error = SELECT_TIMEOUT;      failf(data, "Transfer aborted due to timeout");      break;    default:      /*       * This code previously didn't use the kerberos sec_read() code       * to read, but when we use Curl_read() it may do so. Do confirm       * that this is still ok and then remove this comment!       */      res= Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread,                     &gotbytes);      if(res< 0)        /* EWOULDBLOCK */        continue; /* go loop yourself */      else if(res)        keepon = FALSE;      else if(gotbytes <= 0) {        keepon = FALSE;//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:texlive,代码行数:101,


示例15: Curl_connecthost

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */                          struct Curl_dns_entry *remotehost, /* use this one */                          int port,                  /* connect to this */                          curl_socket_t *sockconn,   /* the connected socket */                          Curl_ipconnect **addr,     /* the one we used */                          bool *connected)           /* really connected? */{  struct SessionHandle *data = conn->data;  int rc;  curl_socket_t sockfd= CURL_SOCKET_BAD;  int aliasindex=0;  char *hostname;  struct timeval after;  struct timeval before = Curl_tvnow();#ifdef ENABLE_IPV6  struct addrinfo *ai;#endif    /*************************************************************   * Figure out what maximum time we have left   *************************************************************/  long timeout_ms=300000; /* milliseconds, default to five minutes */  *connected = FALSE; /* default to not connected */  if(data->set.timeout || data->set.connecttimeout) {    double has_passed;    /* Evaluate in milliseconds how much time that has passed */    has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.start);#ifndef min#define min(a, b)   ((a) < (b) ? (a) : (b))#endif    /* get the most strict timeout of the ones converted to milliseconds */    if(data->set.timeout && data->set.connecttimeout) {      if (data->set.timeout < data->set.connecttimeout)        timeout_ms = data->set.timeout*1000;      else         timeout_ms = data->set.connecttimeout*1000;    }    else if(data->set.timeout)      timeout_ms = data->set.timeout*1000;    else      timeout_ms = data->set.connecttimeout*1000;    /* subtract the passed time */    timeout_ms -= (long)has_passed;    if(timeout_ms < 0) {      /* a precaution, no need to continue if time already is up */      failf(data, "Connection time-out");      return CURLE_OPERATION_TIMEOUTED;    }  }  hostname = data->change.proxy?conn->proxyhost:conn->hostname;  infof(data, "About to connect() to %s port %d/n",        hostname, port);#ifdef ENABLE_IPV6  /*   * Connecting with a getaddrinfo chain   */  for (ai = remotehost->addr; ai; ai = ai->ai_next, aliasindex++) {    sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);    if (sockfd == CURL_SOCKET_BAD)      continue;#else  /*   * Connecting with old style IPv4-only support   */  /* This is the loop that attempts to connect to all IP-addresses we     know for the given host. One by one. */  for(rc=-1, aliasindex=0;      rc && (struct in_addr *)remotehost->addr->h_addr_list[aliasindex];      aliasindex++) {    struct sockaddr_in serv_addr;    /* create an IPv4 TCP socket */    sockfd = socket(AF_INET, SOCK_STREAM, 0);    if(CURL_SOCKET_BAD == sockfd) {      failf(data, "couldn't create socket");      return CURLE_COULDNT_CONNECT; /* big time error */    }    /* nasty address work before connect can be made */    memset((char *) &serv_addr, '/0', sizeof(serv_addr));    memcpy((char *)&(serv_addr.sin_addr),           (struct in_addr *)remotehost->addr->h_addr_list[aliasindex],           sizeof(struct in_addr));    serv_addr.sin_family = remotehost->addr->h_addrtype;    serv_addr.sin_port = htons((unsigned short)port);#endif    if(conn->data->set.device) {//.........这里部分代码省略.........
开发者ID:0culus,项目名称:Doom3-for-MacOSX-,代码行数:101,


示例16: Curl_connecthost

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */                          const struct Curl_dns_entry *remotehost,                          curl_socket_t *sockconn,   /* the connected socket */                          Curl_addrinfo **addr,      /* the one we used */                          bool *connected)           /* really connected? */{    struct SessionHandle *data = conn->data;    curl_socket_t sockfd = CURL_SOCKET_BAD;    int aliasindex;    int num_addr;    Curl_addrinfo *ai;    Curl_addrinfo *curr_addr;    struct timeval after;    struct timeval before = Curl_tvnow();    /*************************************************************     * Figure out what maximum time we have left     *************************************************************/    long timeout_ms;    long timeout_per_addr;    DEBUGASSERT(sockconn);    *connected = FALSE; /* default to not connected */    /* get the timeout left */    timeout_ms = Curl_timeleft(conn, &before, TRUE);    if(timeout_ms < 0) {        /* a precaution, no need to continue if time already is up */        failf(data, "Connection time-out");        return CURLE_OPERATION_TIMEDOUT;    }    Curl_expire(data, timeout_ms);    /* Max time for each address */    num_addr = Curl_num_addresses(remotehost->addr);    timeout_per_addr = timeout_ms / num_addr;    ai = remotehost->addr;    /* Below is the loop that attempts to connect to all IP-addresses we     * know for the given host. One by one until one IP succeeds.     */    if(data->state.used_interface == Curl_if_multi)        /* don't hang when doing multi */        timeout_per_addr = 0;    /*     * Connecting with a Curl_addrinfo chain     */    for (curr_addr = ai, aliasindex=0; curr_addr;            curr_addr = curr_addr->ai_next, aliasindex++) {        /* start connecting to the IP curr_addr points to */        sockfd = singleipconnect(conn, curr_addr, timeout_per_addr, connected);        if(sockfd != CURL_SOCKET_BAD)            break;        /* get a new timeout for next attempt */        after = Curl_tvnow();        timeout_ms -= Curl_tvdiff(after, before);        if(timeout_ms < 0) {            failf(data, "connect() timed out!");            return CURLE_OPERATION_TIMEDOUT;        }        before = after;    }  /* end of connect-to-each-address loop */    *sockconn = sockfd;    /* the socket descriptor we've connected */    if(sockfd == CURL_SOCKET_BAD) {        /* no good connect was made */        failf(data, "couldn't connect to host");        return CURLE_COULDNT_CONNECT;    }    /* leave the socket in non-blocking mode */    /* store the address we use */    if(addr)        *addr = curr_addr;    data->info.numconnects++; /* to track the number of connections made */    return CURLE_OK;}
开发者ID:kreshano,项目名称:curl,代码行数:89,


示例17: Curl_is_connected

CURLcode Curl_is_connected(struct connectdata *conn,                           int sockindex,                           bool *connected){  int rc;  struct SessionHandle *data = conn->data;  CURLcode code = CURLE_OK;  curl_socket_t sockfd = conn->sock[sockindex];  long allow = DEFAULT_CONNECT_TIMEOUT;  long allow_total = 0;  long has_passed;  curlassert(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);  *connected = FALSE; /* a very negative world view is best */  /* Evaluate in milliseconds how much time that has passed */  has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);  /* subtract the most strict timeout of the ones */  if(data->set.timeout && data->set.connecttimeout) {    if (data->set.timeout < data->set.connecttimeout)      allow_total = allow = data->set.timeout*1000;    else      allow = data->set.connecttimeout*1000;  }  else if(data->set.timeout) {    allow_total = allow = data->set.timeout*1000;  }  else if(data->set.connecttimeout) {    allow = data->set.connecttimeout*1000;  }  if(has_passed > allow ) {    /* time-out, bail out, go home */    failf(data, "Connection time-out after %ld ms", has_passed);    return CURLE_OPERATION_TIMEOUTED;  }  if(conn->bits.tcpconnect) {    /* we are connected already! */    Curl_expire(data, allow_total);    *connected = TRUE;    return CURLE_OK;  }  Curl_expire(data, allow);  /* check for connect without timeout as we want to return immediately */  rc = waitconnect(sockfd, 0);  if(WAITCONN_CONNECTED == rc) {    int error;    if (verifyconnect(sockfd, &error)) {      /* we are connected, awesome! */      *connected = TRUE;      return CURLE_OK;    }    /* nope, not connected for real */    data->state.os_errno = error;    infof(data, "Connection failed/n");    if(trynextip(conn, sockindex, connected)) {      code = CURLE_COULDNT_CONNECT;    }  }  else if(WAITCONN_TIMEOUT != rc) {    int error = 0;    /* nope, not connected  */    if (WAITCONN_FDSET_ERROR == rc) {      (void)verifyconnect(sockfd, &error);      data->state.os_errno = error;      infof(data, "%s/n",Curl_strerror(conn,error));    }    else      infof(data, "Connection failed/n");    if(trynextip(conn, sockindex, connected)) {      error = Curl_sockerrno();      data->state.os_errno = error;      failf(data, "Failed connect to %s:%d; %s",            conn->host.name, conn->port, Curl_strerror(conn,error));      code = CURLE_COULDNT_CONNECT;    }  }  /*   * If the connection failed here, we should attempt to connect to the "next   * address" for the given host.   */  return code;}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:91,


示例18: Curl_connecthost

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */                          const struct Curl_dns_entry *remotehost,                          bool *connected)           /* really connected? */{  struct SessionHandle *data = conn->data;  struct timeval after;  struct timeval before = Curl_tvnow();  int i;  /*************************************************************   * Figure out what maximum time we have left   *************************************************************/  long timeout_ms;  *connected = FALSE; /* default to not connected */  /* get the timeout left */  timeout_ms = Curl_timeleft(data, &before, TRUE);  if(timeout_ms < 0) {    /* a precaution, no need to continue if time already is up */    failf(data, "Connection time-out");    return CURLE_OPERATION_TIMEDOUT;  }  conn->num_addr = Curl_num_addresses(remotehost->addr);  conn->tempaddr[0] = remotehost->addr;  conn->tempaddr[1] = remotehost->addr;  /* Below is the loop that attempts to connect to all IP-addresses we   * know for the given host.   * One by one, for each protocol, until one IP succeeds.   */  for(i=0; i<2; i++) {    curl_socket_t sockfd = CURL_SOCKET_BAD;    Curl_addrinfo *ai = conn->tempaddr[i];    int family = i ? AF_INET6 : AF_INET;    /* find first address for this address family, if any */    while(ai && ai->ai_family != family)      ai = ai->ai_next;    /*     * Connecting with a Curl_addrinfo chain     */    while(ai) {      CURLcode res;      /* Max time for the next connection attempt */      conn->timeoutms_per_addr = ai->ai_next == NULL ?                                 timeout_ms : timeout_ms / 2;      /* start connecting to the IP curr_addr points to */      res = singleipconnect(conn, ai, &sockfd, connected);      if(res)        return res;      if(sockfd != CURL_SOCKET_BAD)        break;      /* get a new timeout for next attempt */      after = Curl_tvnow();      timeout_ms -= Curl_tvdiff(after, before);      if(timeout_ms < 0) {        failf(data, "connect() timed out!");        return CURLE_OPERATION_TIMEDOUT;      }      before = after;      /* next addresses */      do {        ai = ai->ai_next;      } while(ai && ai->ai_family != family);    }  /* end of connect-to-each-address loop */    conn->tempsock[i] = sockfd;    conn->tempaddr[i] = ai;  }  if((conn->tempsock[0] == CURL_SOCKET_BAD) &&     (conn->tempsock[1] == CURL_SOCKET_BAD)) {    /* no good connect was made */    failf(data, "couldn't connect to %s at %s:%ld",          conn->bits.proxy?"proxy":"host",          conn->bits.proxy?conn->proxy.name:conn->host.name, conn->port);    return CURLE_COULDNT_CONNECT;  }  /* leave the socket in non-blocking mode */  data->info.numconnects++; /* to track the number of connections made */  return CURLE_OK;}
开发者ID:birmingham,项目名称:curl,代码行数:95,


示例19: Curl_gtls_connect

//.........这里部分代码省略.........  gnutls_transport_set_ptr(session,                           (gnutls_transport_ptr)conn->sock[sockindex]);  /* This might be a reconnect, so we check for a session ID in the cache     to speed up things */  if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize)) {    /* we got a session id, use it! */    gnutls_session_set_data(session, ssl_sessionid, ssl_idsize);    /* Informational message */    infof (data, "SSL re-using session ID/n");  }  do {    rc = gnutls_handshake(session);    if((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) {      long timeout_ms;      long has_passed;      if(data->set.timeout || data->set.connecttimeout) {        /* get the most strict timeout of the ones converted to milliseconds */        if(data->set.timeout &&           (data->set.timeout>data->set.connecttimeout))          timeout_ms = data->set.timeout*1000;        else          timeout_ms = data->set.connecttimeout*1000;      }      else        timeout_ms = DEFAULT_CONNECT_TIMEOUT;      /* Evaluate in milliseconds how much time that has passed */      has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);      /* subtract the passed time */      timeout_ms -= has_passed;      if(timeout_ms < 0) {        /* a precaution, no need to continue if time already is up */        failf(data, "SSL connection timeout");        return CURLE_OPERATION_TIMEOUTED;      }      rc = Curl_select(conn->sock[sockindex],                         conn->sock[sockindex], (int)timeout_ms);      if(rc > 0)        /* reabable or writable, go loop*/        continue;      else if(0 == rc) {        /* timeout */        failf(data, "SSL connection timeout");        return CURLE_OPERATION_TIMEDOUT;      }      else {        /* anything that gets here is fatally bad */        failf(data, "select on SSL socket, errno: %d", Curl_ourerrno());        return CURLE_SSL_CONNECT_ERROR;      }    }    else      break;  } while(1);  if (rc < 0) {    failf(data, "gnutls_handshake() failed: %d", rc);
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:67,


示例20: Curl_SSLConnect

//.........这里部分代码省略.........  connssl->handle = SSL_new(connssl->ctx);  SSL_set_connect_state(connssl->handle);  connssl->server_cert = 0x0;  if(!conn->bits.reuse) {    /* We're not re-using a connection, check if there's a cached ID we       can/should use here! */    if(!Get_SSL_Session(conn, &ssl_sessionid)) {      /* we got a session id, use it! */      SSL_set_session(connssl->handle, ssl_sessionid);      /* Informational message */      infof (data, "SSL re-using session ID/n");    }  }  /* pass the raw socket into the SSL layers */  SSL_set_fd(connssl->handle, sockfd);  while(1) {    fd_set writefd;    fd_set readfd;    struct timeval interval;    long timeout_ms;    /* Find out if any timeout is set. If not, use 300 seconds.       Otherwise, figure out the most strict timeout of the two possible one       and then how much time that has elapsed to know how much time we       allow for the connect call */    if(data->set.timeout || data->set.connecttimeout) {      long has_passed;      /* Evaluate in milliseconds how much time that has passed */      has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.start);      /* get the most strict timeout of the ones converted to milliseconds */      if(data->set.timeout &&         (data->set.timeout>data->set.connecttimeout))        timeout_ms = data->set.timeout*1000;      else        timeout_ms = data->set.connecttimeout*1000;      /* subtract the passed time */      timeout_ms -= has_passed;      if(timeout_ms < 0) {        /* a precaution, no need to continue if time already is up */        failf(data, "SSL connection timeout");        return CURLE_OPERATION_TIMEOUTED;      }    }    else      /* no particular time-out has been set */      timeout_ms= DEFAULT_CONNECT_TIMEOUT;    FD_ZERO(&writefd);    FD_ZERO(&readfd);    err = SSL_connect(connssl->handle);    /* 1  is fine       0  is "not successful but was shut down controlled"       <0 is "handshake was not successful, because a fatal error occurred" */    if(1 != err) {      int detail = SSL_get_error(connssl->handle, err);
开发者ID:yyyyyao,项目名称:Slicer3-lib-mirrors,代码行数:67,


示例21: Curl_is_connected

//.........这里部分代码省略.........        conn->ip_addr = conn->tempaddr[i];        conn->tempsock[i] = CURL_SOCKET_BAD;        /* close the other socket, if open */        if(conn->tempsock[other] != CURL_SOCKET_BAD) {          Curl_closesocket(conn, conn->tempsock[other]);          conn->tempsock[other] = CURL_SOCKET_BAD;        }        /* see if we need to do any proxy magic first once we connected */        result = Curl_connected_proxy(conn, sockindex);        if(result)          return result;        conn->bits.tcpconnect[sockindex] = TRUE;        *connected = TRUE;        if(sockindex == FIRSTSOCKET)          Curl_pgrsTime(data, TIMER_CONNECT); /* connect done */        Curl_updateconninfo(conn, conn->sock[sockindex]);        Curl_verboseconnect(conn);        return CURLE_OK;      }      infof(data, "Connection failed/n");    }    else if(rc & CURL_CSELECT_ERR)      (void)verifyconnect(conn->tempsock[i], &error);    /*     * The connection failed here, we should attempt to connect to the "next     * address" for the given host. But first remember the latest error.     */    if(error) {      data->state.os_errno = error;      SET_SOCKERRNO(error);      if(conn->tempaddr[i]) {        CURLcode status;        char ipaddress[MAX_IPADR_LEN];        Curl_printable_address(conn->tempaddr[i], ipaddress, MAX_IPADR_LEN);        infof(data, "connect to %s port %ld failed: %s/n",              ipaddress, conn->port, Curl_strerror(conn, error));        conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?                                   allow : allow / 2;        status = trynextip(conn, sockindex, i);        if(status != CURLE_COULDNT_CONNECT            || conn->tempsock[other] == CURL_SOCKET_BAD)          /* the last attempt failed and no other sockets remain open */          result = status;      }    }  }  /*   * Now that we've checked whether we are connected, check whether we've   * already timed out.   *   * First figure out how long time we have left to connect */  allow = Curl_timeleft(data, &now, TRUE);  if(allow < 0) {    /* time-out, bail out, go home */    failf(data, "Connection timeout after %ld ms",          Curl_tvdiff(now, data->progress.t_startsingle));    return CURLE_OPERATION_TIMEDOUT;  }  if(result) {    /* no more addresses to try */    const char *hostname;    /* if the first address family runs out of addresses to try before       the happy eyeball timeout, go ahead and try the next family now */    if(conn->tempaddr[1] == NULL) {      result = trynextip(conn, sockindex, 1);      if(!result)        return result;    }    if(conn->bits.socksproxy)      hostname = conn->socks_proxy.host.name;    else if(conn->bits.httpproxy)      hostname = conn->http_proxy.host.name;    else if(conn->bits.conn_to_host)      hostname = conn->conn_to_host.name;    else      hostname = conn->host.name;    failf(data, "Failed to connect to %s port %ld after %ld ms: %s",        hostname, conn->port,        Curl_tvdiff(now, data->progress.t_startsingle),        Curl_strerror(conn, error));  }  return result;}
开发者ID:Metaswitch,项目名称:curl,代码行数:101,


示例22: Curl_wait_for_resolv

/* * Curl_wait_for_resolv() waits for a resolve to finish. This function should * be avoided since using this risk getting the multi interface to "hang". * * If 'entry' is non-NULL, make it point to the resolved dns entry * * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and * CURLE_OPERATION_TIMEDOUT if a time-out occurred. */CURLcode Curl_wait_for_resolv(struct connectdata *conn,                              struct Curl_dns_entry **entry){  CURLcode rc=CURLE_OK;  struct SessionHandle *data = conn->data;  long timeout = CURL_TIMEOUT_RESOLVE; /* default name resolve timeout */  /* now, see if there's a connect timeout or a regular timeout to     use instead of the default one */  if(conn->data->set.connecttimeout)    timeout = conn->data->set.connecttimeout;  else if(conn->data->set.timeout)    timeout = conn->data->set.timeout;  /* We convert the number of seconds into number of milliseconds here: */  if(timeout < 2147483)    /* maximum amount of seconds that can be multiplied with 1000 and       still fit within 31 bits */    timeout *= 1000;  else    timeout = 0x7fffffff; /* ridiculous amount of time anyway */  /* Wait for the name resolve query to complete. */  while (1) {    int nfds=0;    fd_set read_fds, write_fds;    struct timeval *tvp, tv, store;    int count;    struct timeval now = Curl_tvnow();    long timediff;    store.tv_sec = (int)timeout/1000;    store.tv_usec = (timeout%1000)*1000;    FD_ZERO(&read_fds);    FD_ZERO(&write_fds);    nfds = ares_fds(data->state.areschannel, &read_fds, &write_fds);    if (nfds == 0)      /* no file descriptors means we're done waiting */      break;    tvp = ares_timeout(data->state.areschannel, &store, &tv);    count = select(nfds, &read_fds, &write_fds, NULL, tvp);    if (count < 0 && errno != EINVAL)      break;    ares_process(data->state.areschannel, &read_fds, &write_fds);    timediff = Curl_tvdiff(Curl_tvnow(), now); /* spent time */    timeout -= timediff?timediff:1; /* always deduct at least 1 */    if (timeout < 0) {      /* our timeout, so we cancel the ares operation */      ares_cancel(data->state.areschannel);      break;    }  }  /* Operation complete, if the lookup was successful we now have the entry     in the cache. */  if(entry)    *entry = conn->async.dns;  if(!conn->async.dns) {    /* a name was not resolved */    if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) {      failf(data, "Resolving host timed out: %s", conn->host.dispname);      rc = CURLE_OPERATION_TIMEDOUT;    }    else if(conn->async.done) {      failf(data, "Could not resolve host: %s (%s)", conn->host.dispname,            ares_strerror(conn->async.status));      rc = CURLE_COULDNT_RESOLVE_HOST;    }    else      rc = CURLE_OPERATION_TIMEDOUT;    /* close the connection, since we can't return failure here without       cleaning up this connection properly */    conn->bits.close = TRUE;  }  return rc;}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:92,


示例23: Curl_proxyCONNECT

//.........这里部分代码省略.........      }      Curl_safefree(req_buffer);      if(result)        return result;      conn->tunnel_state[sockindex] = TUNNEL_CONNECT;      /* now we've issued the CONNECT and we're waiting to hear back, return         and get called again polling-style */      return CURLE_OK;    } /* END CONNECT PHASE */    { /* BEGIN NEGOTIATION PHASE */      size_t nread;   /* total size read */      int perline; /* count bytes per line */      int keepon=TRUE;      ssize_t gotbytes;      char *ptr;      char *line_start;      ptr=data->state.buffer;      line_start = ptr;      nread=0;      perline=0;      keepon=TRUE;      while((nread<BUFSIZE) && (keepon && !error)) {        /* if timeout is requested, find out how much remaining time we have */        check = timeout - /* timeout time */          Curl_tvdiff(Curl_tvnow(), conn->now); /* spent time */        if(check <= 0) {          failf(data, "Proxy CONNECT aborted due to timeout");          error = SELECT_TIMEOUT; /* already too little time */          break;        }        /* loop every second at least, less if the timeout is near */        switch (Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD,                                  check<1000L?check:1000)) {        case -1: /* select() error, stop reading */          error = SELECT_ERROR;          failf(data, "Proxy CONNECT aborted due to select/poll error");          break;        case 0: /* timeout */          break;        default:          DEBUGASSERT(ptr+BUFSIZE-nread <= data->state.buffer+BUFSIZE+1);          result = Curl_read(conn, tunnelsocket, ptr, BUFSIZE-nread,                             &gotbytes);          if(result==CURLE_AGAIN)            continue; /* go loop yourself */          else if(result)            keepon = FALSE;          else if(gotbytes <= 0) {            keepon = FALSE;            if(data->set.proxyauth && data->state.authproxy.avail) {              /* proxy auth was requested and there was proxy auth available,                 then deem this as "mere" proxy disconnect */              conn->bits.proxy_connect_closed = TRUE;            }            else {              error = SELECT_ERROR;
开发者ID:celesius,项目名称:et-engine,代码行数:67,


示例24: Curl_wait_for_resolv

/* * Curl_wait_for_resolv() waits for a resolve to finish. This function should * be avoided since using this risk getting the multi interface to "hang". * * If 'entry' is non-NULL, make it point to the resolved dns entry * * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and * CURLE_OPERATION_TIMEDOUT if a time-out occurred. */CURLcode Curl_wait_for_resolv(struct connectdata *conn,                              struct Curl_dns_entry **entry){  CURLcode rc=CURLE_OK;  struct SessionHandle *data = conn->data;  long timeout;  struct timeval now = Curl_tvnow();  /* now, see if there's a connect timeout or a regular timeout to     use instead of the default one */  if(conn->data->set.connecttimeout)    timeout = conn->data->set.connecttimeout;  else if(conn->data->set.timeout)    timeout = conn->data->set.timeout;  else    timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */  /* Wait for the name resolve query to complete. */  while(1) {    struct timeval *tvp, tv, store;    long timediff;    int itimeout;    itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;    store.tv_sec = itimeout/1000;    store.tv_usec = (itimeout%1000)*1000;    tvp = ares_timeout(data->state.areschannel, &store, &tv);    /* use the timeout period ares returned to us above */    ares_waitperform(conn, (int)(tvp->tv_sec * 1000 + tvp->tv_usec/1000));    if(conn->async.done)      break;    timediff = Curl_tvdiff(Curl_tvnow(), now); /* spent time */    timeout -= timediff?timediff:1; /* always deduct at least 1 */    if(timeout < 0) {      /* our timeout, so we cancel the ares operation */      ares_cancel(data->state.areschannel);      break;    }  }  /* Operation complete, if the lookup was successful we now have the entry     in the cache. */  if(entry)    *entry = conn->async.dns;  if(!conn->async.dns) {    /* a name was not resolved */    if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) {      failf(data, "Resolving host timed out: %s", conn->host.dispname);      rc = CURLE_COULDNT_RESOLVE_HOST;    }    else if(conn->async.done) {      failf(data, "Could not resolve host: %s (%s)", conn->host.dispname,            ares_strerror(conn->async.status));      rc = CURLE_COULDNT_RESOLVE_HOST;    }    else      rc = CURLE_OPERATION_TIMEDOUT;    /* close the connection, since we can't return failure here without       cleaning up this connection properly */    conn->bits.close = TRUE;  }  return rc;}
开发者ID:DISTRHO,项目名称:DISTRHO-Ports,代码行数:81,


示例25: Curl_resolver_wait_resolv

/* * Curl_resolver_wait_resolv() * * waits for a resolve to finish. This function should be avoided since using * this risk getting the multi interface to "hang". * * If 'entry' is non-NULL, make it point to the resolved dns entry * * Returns CURLE_COULDNT_RESOLVE_HOST if the host was not resolved, and * CURLE_OPERATION_TIMEDOUT if a time-out occurred. */CURLcode Curl_resolver_wait_resolv(struct connectdata *conn,                                   struct Curl_dns_entry **entry){  CURLcode rc=CURLE_OK;  struct SessionHandle *data = conn->data;  long timeout;  struct timeval now = Curl_tvnow();  struct Curl_dns_entry *temp_entry;  timeout = Curl_timeleft(data, &now, TRUE);  if(!timeout)    timeout = CURL_TIMEOUT_RESOLVE * 1000; /* default name resolve timeout */  /* Wait for the name resolve query to complete. */  for(;;) {    struct timeval *tvp, tv, store;    long timediff;    int itimeout;    int timeout_ms;    itimeout = (timeout > (long)INT_MAX) ? INT_MAX : (int)timeout;    store.tv_sec = itimeout/1000;    store.tv_usec = (itimeout%1000)*1000;    tvp = ares_timeout((ares_channel)data->state.resolver, &store, &tv);    /* use the timeout period ares returned to us above if less than one       second is left, otherwise just use 1000ms to make sure the progress       callback gets called frequent enough */    if(!tvp->tv_sec)      timeout_ms = (int)(tvp->tv_usec/1000);    else      timeout_ms = 1000;    waitperform(conn, timeout_ms);    Curl_resolver_is_resolved(conn,&temp_entry);    if(conn->async.done)      break;    if(Curl_pgrsUpdate(conn)) {      rc = CURLE_ABORTED_BY_CALLBACK;      timeout = -1; /* trigger the cancel below */    }    else {      struct timeval now2 = Curl_tvnow();      timediff = Curl_tvdiff(now2, now); /* spent time */      timeout -= timediff?timediff:1; /* always deduct at least 1 */      now = now2; /* for next loop */    }    if(timeout < 0) {      /* our timeout, so we cancel the ares operation */      ares_cancel((ares_channel)data->state.resolver);      break;    }  }  /* Operation complete, if the lookup was successful we now have the entry     in the cache. */  if(entry)    *entry = conn->async.dns;  if(!conn->async.dns) {    /* a name was not resolved */    if((timeout < 0) || (conn->async.status == ARES_ETIMEOUT)) {      if(conn->bits.proxy) {        failf(data, "Resolving proxy timed out: %s", conn->proxy.dispname);        rc = CURLE_COULDNT_RESOLVE_PROXY;      }      else {        failf(data, "Resolving host timed out: %s", conn->host.dispname);        rc = CURLE_COULDNT_RESOLVE_HOST;      }    }    else if(conn->async.done) {      if(conn->bits.proxy) {        failf(data, "Could not resolve proxy: %s (%s)", conn->proxy.dispname,              ares_strerror(conn->async.status));        rc = CURLE_COULDNT_RESOLVE_PROXY;      }      else {        failf(data, "Could not resolve host: %s (%s)", conn->host.dispname,              ares_strerror(conn->async.status));        rc = CURLE_COULDNT_RESOLVE_HOST;      }    }    else//.........这里部分代码省略.........
开发者ID:BinyaminSchein,项目名称:YoutubePlaylistDownloader,代码行数:101,


示例26: Curl_telnet

//.........这里部分代码省略.........        if(events.lNetworkEvents & FD_CLOSE) {          keepon = FALSE;        }      }      break;    }  }  /* We called WSACreateEvent, so call WSACloseEvent */  if (close_event_func(event_handle) == FALSE) {    infof(data,"WSACloseEvent failed (%d)",WSAGetLastError());  }  /* "Forget" pointers into the library we're about to free */  create_event_func = NULL;  close_event_func = NULL;  event_select_func = NULL;  enum_netevents_func = NULL;  /* We called LoadLibrary, so call FreeLibrary */  if (!FreeLibrary(wsock2))    infof(data,"FreeLibrary(wsock2) failed (%d)",GetLastError());#else  FD_ZERO (&readfd);		/* clear it */  FD_SET (sockfd, &readfd);  FD_SET (0, &readfd);  keepfd = readfd;  while (keepon) {    struct timeval interval;    readfd = keepfd;		/* set this every lap in the loop */    interval.tv_sec = 1;    interval.tv_usec = 0;    switch (select (sockfd + 1, &readfd, NULL, NULL, &interval)) {    case -1:			/* error, stop reading */      keepon = FALSE;      continue;    case 0:			/* timeout */      break;    default:			/* read! */      if(FD_ISSET(0, &readfd)) { /* read from stdin */        unsigned char outbuf[2];        int out_count = 0;        ssize_t bytes_written;        char *buffer = buf;                nread = read(0, buf, 255);        while(nread--) {          outbuf[0] = *buffer++;          out_count = 1;          if(outbuf[0] == CURL_IAC)            outbuf[out_count++] = CURL_IAC;                Curl_write(conn, conn->sock[FIRSTSOCKET], outbuf,                     out_count, &bytes_written);        }      }      if(FD_ISSET(sockfd, &readfd)) {        /* This OUGHT to check the return code... */        (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);        /* if we receive 0 or less here, the server closed the connection and           we bail out from this! */        if (nread <= 0) {          keepon = FALSE;          break;        }        telrcv(conn, (unsigned char *)buf, nread);        /* Negotiate if the peer has started negotiating,           otherwise don't. We don't want to speak telnet with           non-telnet servers, like POP or SMTP. */        if(tn->please_negotiate && !tn->already_negotiated) {          negotiate(conn);          tn->already_negotiated = 1;        }      }    }    if(data->set.timeout) {      struct timeval now;           /* current time */      now = Curl_tvnow();      if(Curl_tvdiff(now, conn->created)/1000 >= data->set.timeout) {        failf(data, "Time-out");        code = CURLE_OPERATION_TIMEOUTED;        keepon = FALSE;      }    }  }#endif  /* mark this as "no further transfer wanted" */  Curl_Transfer(conn, -1, -1, FALSE, NULL, -1, NULL);  return code;}
开发者ID:Nekel-Seyew,项目名称:niTech4,代码行数:101,


示例27: handshake

/* this function does a BLOCKING SSL/TLS (re-)handshake */static CURLcode handshake(struct connectdata *conn,                          gnutls_session session,                          int sockindex,                          bool duringconnect){    struct SessionHandle *data = conn->data;    int rc;    do {        rc = gnutls_handshake(session);        if((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) {            long timeout_ms = DEFAULT_CONNECT_TIMEOUT;            long has_passed;            if(duringconnect && data->set.connecttimeout)                timeout_ms = data->set.connecttimeout*1000;            if(data->set.timeout) {                /* get the strictest timeout of the ones converted to milliseconds */                if((data->set.timeout*1000) < timeout_ms)                    timeout_ms = data->set.timeout*1000;            }            /* Evaluate in milliseconds how much time that has passed */            has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);            /* subtract the passed time */            timeout_ms -= has_passed;            if(timeout_ms < 0) {                /* a precaution, no need to continue if time already is up */                failf(data, "SSL connection timeout");                return CURLE_OPERATION_TIMEOUTED;            }            rc = Curl_select(conn->sock[sockindex],                             conn->sock[sockindex], (int)timeout_ms);            if(rc > 0)                /* reabable or writable, go loop*/                continue;            else if(0 == rc) {                /* timeout */                failf(data, "SSL connection timeout");                return CURLE_OPERATION_TIMEDOUT;            }            else {                /* anything that gets here is fatally bad */                failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());                return CURLE_SSL_CONNECT_ERROR;            }        }        else            break;    } while(1);    if (rc < 0) {        failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc));        return CURLE_SSL_CONNECT_ERROR;    }    return CURLE_OK;}
开发者ID:syntheticpp,项目名称:CMakeLua,代码行数:64,


示例28: telnet_do

//.........这里部分代码省略.........          keepon = FALSE;          break;        }        /* returned zero but actually received 0 or less here,           the server closed the connection and we bail out */        else if(nread <= 0) {          keepon = FALSE;          break;        }        result = telrcv(conn, (unsigned char *) buf, nread);        if(result) {          keepon = FALSE;          break;        }        /* Negotiate if the peer has started negotiating,           otherwise don't. We don't want to speak telnet with           non-telnet servers, like POP or SMTP. */        if(tn->please_negotiate && !tn->already_negotiated) {          negotiate(conn);          tn->already_negotiated = 1;        }      }      if(events.lNetworkEvents & FD_CLOSE) {        keepon = FALSE;      }      break;    }    if(data->set.timeout) {      now = Curl_tvnow();      if(Curl_tvdiff(now, conn->created) >= data->set.timeout) {        failf(data, "Time-out");        result = CURLE_OPERATION_TIMEDOUT;        keepon = FALSE;      }    }  }  /* We called WSACreateEvent, so call WSACloseEvent */  if(!close_event_func(event_handle)) {    infof(data, "WSACloseEvent failed (%d)", SOCKERRNO);  }  /* "Forget" pointers into the library we're about to free */  create_event_func = NULL;  close_event_func = NULL;  event_select_func = NULL;  enum_netevents_func = NULL;  /* We called LoadLibrary, so call FreeLibrary */  if(!FreeLibrary(wsock2))    infof(data, "FreeLibrary(wsock2) failed (%d)", ERRNO);#else  pfd[0].fd = sockfd;  pfd[0].events = POLLIN;  if(data->set.is_fread_set) {    poll_cnt = 1;    interval_ms = 100; /* poll user-supplied read function */  }  else {    /* really using fread, so infile is a FILE* */    pfd[1].fd = fileno((FILE *)data->state.in);
开发者ID:AndyUI,项目名称:curl,代码行数:67,


示例29: Curl_connecthost

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */                          const struct Curl_dns_entry *remotehost, /* use this one */                          curl_socket_t *sockconn,   /* the connected socket */                          Curl_addrinfo **addr,      /* the one we used */                          bool *connected)           /* really connected? */{  struct SessionHandle *data = conn->data;  curl_socket_t sockfd = CURL_SOCKET_BAD;  int aliasindex;  int num_addr;  Curl_addrinfo *ai;  Curl_addrinfo *curr_addr;  struct timeval after;  struct timeval before = Curl_tvnow();  /*************************************************************   * Figure out what maximum time we have left   *************************************************************/  long timeout_ms= DEFAULT_CONNECT_TIMEOUT;  long timeout_per_addr;  *connected = FALSE; /* default to not connected */  if(data->set.timeout || data->set.connecttimeout) {    long has_passed;    /* Evaluate in milliseconds how much time that has passed */    has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);#ifndef min#define min(a, b)   ((a) < (b) ? (a) : (b))#endif    /* get the most strict timeout of the ones converted to milliseconds */    if(data->set.timeout && data->set.connecttimeout) {      if (data->set.timeout < data->set.connecttimeout)        timeout_ms = data->set.timeout*1000;      else        timeout_ms = data->set.connecttimeout*1000;    }    else if(data->set.timeout)      timeout_ms = data->set.timeout*1000;    else      timeout_ms = data->set.connecttimeout*1000;    /* subtract the passed time */    timeout_ms -= has_passed;    if(timeout_ms < 0) {      /* a precaution, no need to continue if time already is up */      failf(data, "Connection time-out");      return CURLE_OPERATION_TIMEOUTED;    }  }  Curl_expire(data, timeout_ms);  /* Max time for each address */  num_addr = Curl_num_addresses(remotehost->addr);  timeout_per_addr = timeout_ms / num_addr;  ai = remotehost->addr;  /* Below is the loop that attempts to connect to all IP-addresses we   * know for the given host. One by one until one IP succeeds.   */  if(data->state.used_interface == Curl_if_multi)    /* don't hang when doing multi */    timeout_per_addr = 0;  /*   * Connecting with a Curl_addrinfo chain   */  for (curr_addr = ai, aliasindex=0; curr_addr;       curr_addr = curr_addr->ai_next, aliasindex++) {    /* start connecting to the IP curr_addr points to */    sockfd = singleipconnect(conn, curr_addr, timeout_per_addr, connected);    if(sockfd != CURL_SOCKET_BAD)      break;    /* get a new timeout for next attempt */    after = Curl_tvnow();    timeout_ms -= Curl_tvdiff(after, before);    if(timeout_ms < 0) {      failf(data, "connect() timed out!");      return CURLE_OPERATION_TIMEOUTED;    }    before = after;  }  /* end of connect-to-each-address loop */  if (sockfd == CURL_SOCKET_BAD) {    /* no good connect was made */    *sockconn = CURL_SOCKET_BAD;    failf(data, "couldn't connect to host");    return CURLE_COULDNT_CONNECT;  }//.........这里部分代码省略.........
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:101,


示例30: Curl_connecthost

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */                          struct Curl_dns_entry *remotehost, /* use this one */                          int port,                  /* connect to this */                          int *sockconn,             /* the connected socket */                          Curl_ipconnect **addr,     /* the one we used */                          bool *connected)           /* really connected? */{  struct SessionHandle *data = conn->data;  int rc;  int sockfd=-1;  int aliasindex=0;  char *hostname;  struct timeval after;  struct timeval before = Curl_tvnow();  /*************************************************************   * Figure out what maximum time we have left   *************************************************************/  long timeout_ms=300000; /* milliseconds, default to five minutes */  *connected = FALSE; /* default to not connected */  if(data->set.timeout || data->set.connecttimeout) {    double has_passed;    /* Evaluate in milliseconds how much time that has passed */    has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.start);#ifndef min#define min(a, b)   ((a) < (b) ? (a) : (b))#endif    /* get the most strict timeout of the ones converted to milliseconds */    if(data->set.timeout && data->set.connecttimeout) {      if (data->set.timeout < data->set.connecttimeout)        timeout_ms = data->set.timeout*1000;      else         timeout_ms = data->set.connecttimeout*1000;    }    else if(data->set.timeout)      timeout_ms = data->set.timeout*1000;    else      timeout_ms = data->set.connecttimeout*1000;    /* subtract the passed time */    timeout_ms -= (long)has_passed;    if(timeout_ms < 0) {      /* a precaution, no need to continue if time already is up */      failf(data, "Connection time-out");      return CURLE_OPERATION_TIMEOUTED;    }  }  hostname = data->change.proxy?conn->proxyhost:conn->hostname;  infof(data, "About to connect() to %s%s%s:%d/n",        conn->bits.ipv6_ip?"[":"",        hostname,        conn->bits.ipv6_ip?"]":"",        port);#ifdef ENABLE_IPV6  /*   * Connecting with IPv6 support is so much easier and cleanly done   */  {    struct addrinfo *ai;    port =0; /* prevent compiler warning */    for (ai = remotehost->addr; ai; ai = ai->ai_next, aliasindex++) {      sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);      if (sockfd < 0)        continue;      if(conn->data->set.device) {        /* user selected to bind the outgoing socket to a specified "device"           before doing connect */        CURLcode res = bindlocal(conn, sockfd);        if(res)          return res;      }      /* set socket non-blocking */      Curl_nonblock(sockfd, TRUE);      rc = connect(sockfd, ai->ai_addr, ai->ai_addrlen);      if(-1 == rc) {        int error=Curl_ourerrno();        switch (error) {        case EINPROGRESS:        case EWOULDBLOCK:#if defined(EAGAIN) && EAGAIN != EWOULDBLOCK          /* On some platforms EAGAIN and EWOULDBLOCK are the           * same value, and on others they are different, hence           * the odd #if           */        case EAGAIN://.........这里部分代码省略.........
开发者ID:Arkshine,项目名称:NS,代码行数:101,



注:本文中的Curl_tvdiff函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ Curl_tvnow函数代码示例
C++ Curl_timeleft函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。