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

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

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

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

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

示例1: singleipconnect

/* * singleipconnect() * * Note that even on connect fail it returns CURLE_OK, but with 'sock' set to * CURL_SOCKET_BAD. Other errors will however return proper errors. * * singleipconnect() connects to the given IP only, and it may return without * having connected if used from the multi interface. */static CURLcodesingleipconnect(struct connectdata *conn,                const Curl_addrinfo *ai,                long timeout_ms,                curl_socket_t *sockp,                bool *connected){  struct Curl_sockaddr_ex addr;  int rc;  int error = 0;  bool isconnected = FALSE;  struct SessionHandle *data = conn->data;  curl_socket_t sockfd;  CURLcode res = CURLE_OK;  *sockp = CURL_SOCKET_BAD;  *connected = FALSE; /* default is not connected */  res = Curl_socket(conn, ai, &addr, &sockfd);  if(res)    return res;  /* store remote address and port used in this connection attempt */  if(!getaddressinfo((struct sockaddr*)&addr.sa_addr,                     conn->primary_ip, &conn->primary_port)) {    /* malformed address or bug in inet_ntop, try next address */    error = ERRNO;    failf(data, "sa_addr inet_ntop() failed with errno %d: %s",          error, Curl_strerror(conn, error));    Curl_closesocket(conn, sockfd);    return CURLE_OK;  }  memcpy(conn->ip_addr_str, conn->primary_ip, MAX_IPADR_LEN);  infof(data, "  Trying %s.../n", conn->ip_addr_str);  Curl_persistconninfo(conn);  if(data->set.tcp_nodelay)    tcpnodelay(conn, sockfd);  nosigpipe(conn, sockfd);  Curl_sndbufset(sockfd);  if(data->set.fsockopt) {    /* activate callback for setting socket options */    error = data->set.fsockopt(data->set.sockopt_client,                               sockfd,                               CURLSOCKTYPE_IPCXN);    if(error == CURL_SOCKOPT_ALREADY_CONNECTED)      isconnected = TRUE;    else if(error) {      Curl_closesocket(conn, sockfd); /* close the socket and bail out */      return CURLE_ABORTED_BY_CALLBACK;    }  }  /* possibly bind the local end to an IP, interface or port */  res = bindlocal(conn, sockfd, addr.family);  if(res) {    Curl_closesocket(conn, sockfd); /* close socket and bail out */    return res;  }  /* set socket non-blocking */  curlx_nonblock(sockfd, TRUE);  /* Connect TCP sockets, bind UDP */  if(!isconnected && (conn->socktype == SOCK_STREAM)) {    rc = connect(sockfd, &addr.sa_addr, addr.addrlen);    if(-1 == rc)      error = SOCKERRNO;    conn->connecttime = Curl_tvnow();    if(conn->num_addr > 1)      Curl_expire(data, conn->timeoutms_per_addr);  }  else    rc = 0;  if(-1 == rc) {    switch (error) {    case EINPROGRESS:    case EWOULDBLOCK:#if defined(EAGAIN)#if (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:lorenzo,项目名称:curl,代码行数:101,


示例2: Curl_pp_vsendf

/*********************************************************************** * * Curl_pp_vsendf() * * Send the formated string as a command to a pingpong server. Note that * the string should not have any CRLF appended, as this function will * append the necessary things itself. * * made to never block */CURLcode Curl_pp_vsendf(struct pingpong *pp,                        const char *fmt,                        va_list args){  ssize_t bytes_written;  size_t write_len;  char *fmt_crlf;  char *s;  CURLcode result;  struct connectdata *conn = pp->conn;  struct Curl_easy *data = conn->data;#ifdef HAVE_GSSAPI  enum protection_level data_sec = conn->data_prot;#endif  DEBUGASSERT(pp->sendleft == 0);  DEBUGASSERT(pp->sendsize == 0);  DEBUGASSERT(pp->sendthis == NULL);  fmt_crlf = aprintf("%s/r/n", fmt); /* append a trailing CRLF */  if(!fmt_crlf)    return CURLE_OUT_OF_MEMORY;  s = vaprintf(fmt_crlf, args); /* trailing CRLF appended */  free(fmt_crlf);  if(!s)    return CURLE_OUT_OF_MEMORY;  bytes_written = 0;  write_len = strlen(s);  Curl_pp_init(pp);  result = Curl_convert_to_network(data, s, write_len);  /* Curl_convert_to_network calls failf if unsuccessful */  if(result) {    free(s);    return result;  }#ifdef HAVE_GSSAPI  conn->data_prot = PROT_CMD;#endif  result = Curl_write(conn, conn->sock[FIRSTSOCKET], s, write_len,                     &bytes_written);#ifdef HAVE_GSSAPI  DEBUGASSERT(data_sec > PROT_NONE && data_sec < PROT_LAST);  conn->data_prot = data_sec;#endif  if(result) {    free(s);    return result;  }  if(conn->data->set.verbose)    Curl_debug(conn->data, CURLINFO_HEADER_OUT,               s, (size_t)bytes_written, conn);  if(bytes_written != (ssize_t)write_len) {    /* the whole chunk was not sent, keep it around and adjust sizes */    pp->sendthis = s;    pp->sendsize = write_len;    pp->sendleft = write_len - bytes_written;  }  else {    free(s);    pp->sendthis = NULL;    pp->sendleft = pp->sendsize = 0;    pp->response = Curl_tvnow();  }  return CURLE_OK;}
开发者ID:ak-ambi,项目名称:CMake,代码行数:85,


示例3: 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 ) {
开发者ID:AdrienJaguenet,项目名称:Enemy-Territory,代码行数:67,


示例4: 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(rc)    /* 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.    */    conn->bits.close = TRUE;  return rc;}
开发者ID:smices,项目名称:XSpeeder,代码行数:84,


示例5: smtp_done

/*********************************************************************** * * smtp_done() * * The DONE function. This does what needs to be done after a single DO has * performed. * * Input argument is already checked for validity. */static CURLcode smtp_done(struct connectdata *conn, CURLcode status,                          bool premature){  CURLcode result = CURLE_OK;  struct SessionHandle *data = conn->data;  struct SMTP *smtp = data->state.proto.smtp;  ssize_t bytes_written;  (void)premature;  if(!smtp)    /* When the easy handle is removed from the multi interface while libcurl       is still trying to resolve the host name, the SMTP struct is not yet       initialized. However, the removal action calls Curl_done() which in       turn calls this function, so we simply return success. */    return CURLE_OK;  if(status) {    conn->bits.close = TRUE; /* marked for closure */    result = status;         /* use the already set error code */  }  else if(!data->set.connect_only) {    struct smtp_conn *smtpc = &conn->proto.smtpc;    struct pingpong *pp = &smtpc->pp;    /* Send the end of block data */    result = Curl_write(conn,                        conn->writesockfd,  /* socket to send to */                        SMTP_EOB,           /* buffer pointer */                        SMTP_EOB_LEN,       /* buffer size */                        &bytes_written);    /* actually sent away */    if(result)      return result;    if(bytes_written != SMTP_EOB_LEN) {      /* The whole chunk was not sent so keep it around and adjust the         pingpong structure accordingly */      pp->sendthis = strdup(SMTP_EOB);      pp->sendsize = SMTP_EOB_LEN;      pp->sendleft = SMTP_EOB_LEN - bytes_written;    }    else      /* Successfully sent so adjust the response timeout relative to now */      pp->response = Curl_tvnow();    state(conn, SMTP_POSTDATA);    /* Run the state-machine       TODO: when the multi interface is used, this _really_ should be using       the smtp_multi_statemach function but we have no general support for       non-blocking DONE operations, not in the multi state machine and with       Curl_done() invokes on several places in the code!    */    result = smtp_block_statemach(conn);  }  /* Clear the transfer mode for the next request */  smtp->transfer = FTPTRANSFER_BODY;  return result;}
开发者ID:Web5design,项目名称:curl,代码行数:72,


示例6: singleipconnect

/* * singleipconnect() * * Note that even on connect fail it returns CURLE_OK, but with 'sock' set to * CURL_SOCKET_BAD. Other errors will however return proper errors. * * singleipconnect() connects to the given IP only, and it may return without * having connected. */static CURLcode singleipconnect(struct connectdata *conn,                                const Curl_addrinfo *ai,                                curl_socket_t *sockp){  struct Curl_sockaddr_ex addr;  int rc = -1;  int error = 0;  bool isconnected = FALSE;  struct SessionHandle *data = conn->data;  curl_socket_t sockfd;  CURLcode result;  char ipaddress[MAX_IPADR_LEN];  long port;  bool is_tcp;  *sockp = CURL_SOCKET_BAD;  result = Curl_socket(conn, ai, &addr, &sockfd);  if(result)    /* Failed to create the socket, but still return OK since we signal the       lack of socket as well. This allows the parent function to keep looping       over alternative addresses/socket families etc. */    return CURLE_OK;  /* store remote address and port used in this connection attempt */  if(!getaddressinfo((struct sockaddr*)&addr.sa_addr,                     ipaddress, &port)) {    /* malformed address or bug in inet_ntop, try next address */    error = ERRNO;    failf(data, "sa_addr inet_ntop() failed with errno %d: %s",          error, Curl_strerror(conn, error));    Curl_closesocket(conn, sockfd);    return CURLE_OK;  }  infof(data, "  Trying %s.../n", ipaddress);#ifdef ENABLE_IPV6  is_tcp = (addr.family == AF_INET || addr.family == AF_INET6) &&    addr.socktype == SOCK_STREAM;#else  is_tcp = (addr.family == AF_INET) && addr.socktype == SOCK_STREAM;#endif  if(is_tcp && data->set.tcp_nodelay)    Curl_tcpnodelay(conn, sockfd);  nosigpipe(conn, sockfd);  Curl_sndbufset(sockfd);  if(is_tcp && data->set.tcp_keepalive)    tcpkeepalive(data, sockfd);  if(data->set.fsockopt) {    /* activate callback for setting socket options */    error = data->set.fsockopt(data->set.sockopt_client,                               sockfd,                               CURLSOCKTYPE_IPCXN);    if(error == CURL_SOCKOPT_ALREADY_CONNECTED)      isconnected = TRUE;    else if(error) {      Curl_closesocket(conn, sockfd); /* close the socket and bail out */      return CURLE_ABORTED_BY_CALLBACK;    }  }  /* possibly bind the local end to an IP, interface or port */  if(addr.family == AF_INET#ifdef ENABLE_IPV6     || addr.family == AF_INET6#endif    ) {    result = bindlocal(conn, sockfd, addr.family,                       Curl_ipv6_scope((struct sockaddr*)&addr.sa_addr));    if(result) {      Curl_closesocket(conn, sockfd); /* close socket and bail out */      if(result == CURLE_UNSUPPORTED_PROTOCOL) {        /* The address family is not supported on this interface.           We can continue trying addresses */        return CURLE_COULDNT_CONNECT;      }      return result;    }  }  /* set socket non-blocking */  (void)curlx_nonblock(sockfd, TRUE);  conn->connecttime = Curl_tvnow();  if(conn->num_addr > 1)    Curl_expire_latest(data, conn->timeoutms_per_addr);//.........这里部分代码省略.........
开发者ID:m-deckel,项目名称:curl,代码行数:101,


示例7: file_upload

static CURLcode file_upload(struct connectdata *conn){  struct FILEPROTO *file = conn->data->state.proto.file;  const char *dir = strchr(file->path, DIRSEP);  FILE *fp;  CURLcode res=CURLE_OK;  struct SessionHandle *data = conn->data;  char *buf = data->state.buffer;  size_t nread;  size_t nwrite;  curl_off_t bytecount = 0;  struct timeval now = Curl_tvnow();  struct_stat file_stat;  const char* buf2;  /*   * Since FILE: doesn't do the full init, we need to provide some extra   * assignments here.   */  conn->fread_func = data->set.fread_func;  conn->fread_in = data->set.in;  conn->data->req.upload_fromhere = buf;  if(!dir)    return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */  if(!dir[1])     return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */  if(data->state.resume_from)    fp = fopen( file->path, "ab" );  else {    int fd;#ifdef DOS_FILESYSTEM    fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY,              conn->data->set.new_file_perms);#else    fd = open(file->path, O_WRONLY|O_CREAT|O_TRUNC,              conn->data->set.new_file_perms);#endif    if(fd < 0) {      failf(data, "Can't open %s for writing", file->path);      return CURLE_WRITE_ERROR;    }    fp = fdopen(fd, "wb");  }  if(!fp) {    failf(data, "Can't open %s for writing", file->path);    return CURLE_WRITE_ERROR;  }  if(-1 != data->set.infilesize)    /* known size of data to "upload" */    Curl_pgrsSetUploadSize(data, data->set.infilesize);  /* treat the negative resume offset value as the case of "-" */  if(data->state.resume_from < 0) {    if(stat(file->path, &file_stat)) {      fclose(fp);      failf(data, "Can't get the size of %s", file->path);      return CURLE_WRITE_ERROR;    }    else      data->state.resume_from = (curl_off_t)file_stat.st_size;  }  while(res == CURLE_OK) {    int readcount;    res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount);    if(res)      break;    if(readcount <= 0)  /* fix questionable compare error. curlvms */      break;    nread = (size_t)readcount;    /*skip bytes before resume point*/    if(data->state.resume_from) {      if( (curl_off_t)nread <= data->state.resume_from ) {        data->state.resume_from -= nread;        nread = 0;        buf2 = buf;      }      else {        buf2 = buf + data->state.resume_from;        nread -= (size_t)data->state.resume_from;        data->state.resume_from = 0;      }    }    else      buf2 = buf;    /* write the data to the target */    nwrite = fwrite(buf2, 1, nread, fp);    if(nwrite != nread) {      res = CURLE_SEND_ERROR;      break;//.........这里部分代码省略.........
开发者ID:RayPlante,项目名称:usvirtualobservatory,代码行数:101,


示例8: Curl_output_digest

CURLcode Curl_output_digest(struct connectdata *conn,                            bool proxy,                            unsigned char *request,                            unsigned char *uripath){  /* We have a Digest setup for this, use it!  Now, to get all the details for     this sorted out, I must urge you dear friend to read up on the RFC2617     section 3.2.2, */  unsigned char md5buf[16]; /* 16 bytes/128 bits */  unsigned char request_digest[33];  unsigned char *md5this;  unsigned char *ha1;  unsigned char ha2[33];/* 32 digits and 1 zero byte */  char cnoncebuf[7];  char *cnonce;  char *tmp = NULL;  struct timeval now;  char **allocuserpwd;  char *userp;  char *passwdp;  struct auth *authp;  struct SessionHandle *data = conn->data;  struct digestdata *d;  if(proxy) {    d = &data->state.proxydigest;    allocuserpwd = &conn->allocptr.proxyuserpwd;    userp = conn->proxyuser;    passwdp = conn->proxypasswd;    authp = &data->state.authproxy;  }  else {    d = &data->state.digest;    allocuserpwd = &conn->allocptr.userpwd;    userp = conn->user;    passwdp = conn->passwd;    authp = &data->state.authhost;  }  /* not set means empty */  if(!userp)    userp=(char *)"";  if(!passwdp)    passwdp=(char *)"";  if(!d->nonce) {    authp->done = FALSE;    return CURLE_OK;  }  authp->done = TRUE;  if(!d->nc)    d->nc = 1;  if(!d->cnonce) {    /* Generate a cnonce */    now = Curl_tvnow();    snprintf(cnoncebuf, sizeof(cnoncebuf), "%06ld", now.tv_sec);    if(Curl_base64_encode(cnoncebuf, strlen(cnoncebuf), &cnonce))      d->cnonce = cnonce;    else      return CURLE_OUT_OF_MEMORY;  }  /*    if the algorithm is "MD5" or unspecified (which then defaults to MD5):    A1 = unq(username-value) ":" unq(realm-value) ":" passwd    if the algorithm is "MD5-sess" then:    A1 = H( unq(username-value) ":" unq(realm-value) ":" passwd )         ":" unq(nonce-value) ":" unq(cnonce-value)  */  md5this = (unsigned char *)    aprintf("%s:%s:%s", userp, d->realm, passwdp);  if(!md5this)    return CURLE_OUT_OF_MEMORY;  Curl_md5it(md5buf, md5this);  free(md5this); /* free this again */  ha1 = (unsigned char *)malloc(33); /* 32 digits and 1 zero byte */  if(!ha1)    return CURLE_OUT_OF_MEMORY;  md5_to_ascii(md5buf, ha1);  if(d->algo == CURLDIGESTALGO_MD5SESS) {    /* nonce and cnonce are OUTSIDE the hash */    tmp = aprintf("%s:%s:%s", ha1, d->nonce, d->cnonce);    free(ha1);    if(!tmp)      return CURLE_OUT_OF_MEMORY;    ha1 = (unsigned char *)tmp;  }//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:101,


示例9: 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:LTears,项目名称:rktotal,代码行数:81,


示例10: Curl_is_connected

CURLcode Curl_is_connected(struct connectdata *conn,                           int sockindex,                           bool *connected){  struct SessionHandle *data = conn->data;  CURLcode code = CURLE_OK;  long allow = DEFAULT_CONNECT_TIMEOUT;  int error = 0;  struct timeval now;  int result;  int i;  DEBUGASSERT(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);  *connected = FALSE; /* a very negative world view is best */  if(conn->bits.tcpconnect[sockindex]) {    /* we are connected already! */    *connected = TRUE;    return CURLE_OK;  }  now = Curl_tvnow();  /* 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 time-out");    return CURLE_OPERATION_TIMEDOUT;  }  for(i=0; i<2; i++) {    if(conn->tempsock[i] == CURL_SOCKET_BAD)      continue;#ifdef mpeix    /* Call this function once now, and ignore the results. We do this to       "clear" the error state on the socket so that we can later read it       reliably. This is reported necessary on the MPE/iX operating system. */    (void)verifyconnect(conn->tempsock[i], NULL);#endif    /* check socket for connect */    result = Curl_socket_ready(CURL_SOCKET_BAD, conn->tempsock[i], 0);    switch(result) {    case 0: /* no connection yet */      if(curlx_tvdiff(now, conn->connecttime) >= conn->timeoutms_per_addr) {        infof(data, "After %ldms connect time, move on!/n",              conn->timeoutms_per_addr);        error = ETIMEDOUT;      }      break;    case CURL_CSELECT_OUT:      if(verifyconnect(conn->tempsock[i], &error)) {        /* we are connected with TCP, awesome! */        int other = i ^ 1;        /* use this socket from now on */        conn->sock[sockindex] = conn->tempsock[i];        conn->ip_addr = conn->tempaddr[i];        /* close the other socket, if open */        if(conn->tempsock[other] != CURL_SOCKET_BAD) {          if(conn->fclosesocket)            conn->fclosesocket(conn->closesocket_client,                               conn->tempsock[other]);          else            sclose(conn->tempsock[other]);        }        /* see if we need to do any proxy magic first once we connected */        code = Curl_connected_proxy(conn, sockindex);        if(code)          return code;        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;      }      else        infof(data, "Connection failed/n");      break;    case CURL_CSELECT_ERR|CURL_CSELECT_OUT:      (void)verifyconnect(conn->tempsock[i], &error);      break;    default:      infof(data, "Whut?/n");      return CURLE_OK;//.........这里部分代码省略.........
开发者ID:birmingham,项目名称:curl,代码行数:101,


示例11: 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,


示例12: 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,


示例13: Curl_connecthost

CURLcode Curl_connecthost(struct connectdata *conn,  /* context */                          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;    }  }  /* 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;  }  /* leave the socket in non-blocking mode *///.........这里部分代码省略.........
开发者ID:elambert,项目名称:honeycomb,代码行数:101,


示例14: 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 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 = data->set.timeout*1000;    else      allow = data->set.connecttimeout*1000;  }  else if(data->set.timeout) {    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! */    *connected = TRUE;    return CURLE_OK;  }  /* 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) {      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_ourerrno();      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:elambert,项目名称:honeycomb,代码行数:87,


示例15: file_upload

static CURLcode file_upload(struct connectdata *conn){  struct FILEPROTO *file = conn->data->req.protop;  const char *dir = strchr(file->path, DIRSEP);  int fd;  int mode;  CURLcode result = CURLE_OK;  struct Curl_easy *data = conn->data;  char *buf = data->state.buffer;  size_t nread;  size_t nwrite;  curl_off_t bytecount = 0;  struct timeval now = Curl_tvnow();  struct_stat file_stat;  const char *buf2;  /*   * Since FILE: doesn't do the full init, we need to provide some extra   * assignments here.   */  conn->data->req.upload_fromhere = buf;  if(!dir)    return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */  if(!dir[1])    return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */#ifdef O_BINARY#define MODE_DEFAULT O_WRONLY|O_CREAT|O_BINARY#else#define MODE_DEFAULT O_WRONLY|O_CREAT#endif  if(data->state.resume_from)    mode = MODE_DEFAULT|O_APPEND;  else    mode = MODE_DEFAULT|O_TRUNC;  fd = open(file->path, mode, conn->data->set.new_file_perms);  if(fd < 0) {    failf(data, "Can't open %s for writing", file->path);    return CURLE_WRITE_ERROR;  }  if(-1 != data->state.infilesize)    /* known size of data to "upload" */    Curl_pgrsSetUploadSize(data, data->state.infilesize);  /* treat the negative resume offset value as the case of "-" */  if(data->state.resume_from < 0) {    if(fstat(fd, &file_stat)) {      close(fd);      failf(data, "Can't get the size of %s", file->path);      return CURLE_WRITE_ERROR;    }    else      data->state.resume_from = (curl_off_t)file_stat.st_size;  }  while(!result) {    int readcount;    result = Curl_fillreadbuffer(conn, BUFSIZE, &readcount);    if(result)      break;    if(readcount <= 0)  /* fix questionable compare error. curlvms */      break;    nread = (size_t)readcount;    /*skip bytes before resume point*/    if(data->state.resume_from) {      if((curl_off_t)nread <= data->state.resume_from) {        data->state.resume_from -= nread;        nread = 0;        buf2 = buf;      }      else {        buf2 = buf + data->state.resume_from;        nread -= (size_t)data->state.resume_from;        data->state.resume_from = 0;      }    }    else      buf2 = buf;    /* write the data to the target */    nwrite = write(fd, buf2, nread);    if(nwrite != nread) {      result = CURLE_SEND_ERROR;      break;    }    bytecount += nread;    Curl_pgrsSetUploadCounter(data, bytecount);    if(Curl_pgrsUpdate(conn))      result = CURLE_ABORTED_BY_CALLBACK;//.........这里部分代码省略.........
开发者ID:Unity-Technologies,项目名称:curl,代码行数:101,


示例16: telnet_do

//.........这里部分代码省略.........        else if(result) {          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* */
开发者ID:chengdong0421,项目名称:curl,代码行数:67,


示例17: file_upload

static CURLcode file_upload(struct connectdata *conn){  struct FILEPROTO *file = conn->proto.file;  char *dir = strchr(file->path, DIRSEP);  FILE *fp;  CURLcode res=CURLE_OK;  struct SessionHandle *data = conn->data;  char *buf = data->state.buffer;  size_t nread;  size_t nwrite;  curl_off_t bytecount = 0;  struct timeval now = Curl_tvnow();  /*   * Since FILE: doesn't do the full init, we need to provide some extra   * assignments here.   */  conn->fread = data->set.fread;  conn->fread_in = data->set.in;  conn->upload_fromhere = buf;  if(!dir)    return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */  if(!dir[1])     return CURLE_FILE_COULDNT_READ_FILE; /* fix: better error code */  fp = fopen(file->path, "wb");  if(!fp) {    failf(data, "Can't open %s for writing", file->path);    return CURLE_WRITE_ERROR;  }  if(-1 != data->set.infilesize)    /* known size of data to "upload" */    Curl_pgrsSetUploadSize(data, data->set.infilesize);  while (res == CURLE_OK) {    int readcount;    res = Curl_fillreadbuffer(conn, BUFSIZE, &readcount);    if(res)      break;    nread = (size_t)readcount;    if (nread <= 0)      break;    /* write the data to the target */    nwrite = fwrite(buf, 1, nread, fp);    if(nwrite != nread) {      res = CURLE_SEND_ERROR;      break;    }    bytecount += nread;    Curl_pgrsSetUploadCounter(data, bytecount);    if(Curl_pgrsUpdate(conn))      res = CURLE_ABORTED_BY_CALLBACK;    else      res = Curl_speedcheck(data, now);  }  if(!res && Curl_pgrsUpdate(conn))    res = CURLE_ABORTED_BY_CALLBACK;  fclose(fp);  return res;}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:71,


示例18: telnet_do

//.........这里部分代码省略.........          /* This reallu OUGHT to check its return code. */          (void)Curl_read(conn, sockfd, buf, BUFSIZE - 1, &nread);          telrcv(conn, (unsigned char *)buf, nread);          fflush(stdout);          /* 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;    }  }  /* 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 */        nread = read(0, buf, 255);        code = send_telnet_data(conn, buf, nread);	if(code) {          keepon = FALSE;	  break;	}      }      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:404UserNotFound,项目名称:sourcemod,代码行数:101,


示例19: Curl_is_connected

CURLcode Curl_is_connected(struct connectdata *conn,                           int sockindex,                           bool *connected){  struct SessionHandle *data = conn->data;  CURLcode result = CURLE_OK;  long allow;  int error = 0;  struct timeval now;  int rc;  int i;  DEBUGASSERT(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);  *connected = FALSE; /* a very negative world view is best */  if(conn->bits.tcpconnect[sockindex]) {    /* we are connected already! */    *connected = TRUE;    return CURLE_OK;  }  now = Curl_tvnow();  /* 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 time-out");    return CURLE_OPERATION_TIMEDOUT;  }  for(i=0; i<2; i++) {    const int other = i ^ 1;    if(conn->tempsock[i] == CURL_SOCKET_BAD)      continue;#ifdef mpeix    /* Call this function once now, and ignore the results. We do this to       "clear" the error state on the socket so that we can later read it       reliably. This is reported necessary on the MPE/iX operating system. */    (void)verifyconnect(conn->tempsock[i], NULL);#endif    /* check socket for connect */    rc = Curl_socket_ready(CURL_SOCKET_BAD, conn->tempsock[i], 0);    if(rc == 0) { /* no connection yet */      error = 0;      if(curlx_tvdiff(now, conn->connecttime) >= conn->timeoutms_per_addr) {        infof(data, "After %ldms connect time, move on!/n",              conn->timeoutms_per_addr);        error = ETIMEDOUT;      }      /* should we try another protocol family? */      if(i == 0 && conn->tempaddr[1] == NULL &&         curlx_tvdiff(now, conn->connecttime) >= HAPPY_EYEBALLS_TIMEOUT) {        trynextip(conn, sockindex, 1);      }    }    else if(rc == CURL_CSELECT_OUT || conn->bits.tcp_fastopen) {      if(verifyconnect(conn->tempsock[i], &error)) {        /* we are connected with TCP, awesome! */        /* use this socket from now on */        conn->sock[sockindex] = conn->tempsock[i];        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;      }      else        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//.........这里部分代码省略.........
开发者ID:m-deckel,项目名称:curl,代码行数:101,


示例20: singleipconnect

/* * singleipconnect() * * Note that even on connect fail it returns CURLE_OK, but with 'sock' set to * CURL_SOCKET_BAD. Other errors will however return proper errors. * * singleipconnect() connects to the given IP only, and it may return without * having connected. */static CURLcodesingleipconnect(struct connectdata *conn,                const Curl_addrinfo *ai,                curl_socket_t *sockp,                bool *connected){  struct Curl_sockaddr_ex addr;  int rc;  int error = 0;  bool isconnected = FALSE;  struct SessionHandle *data = conn->data;  curl_socket_t sockfd;  CURLcode res = CURLE_OK;  *sockp = CURL_SOCKET_BAD;  *connected = FALSE; /* default is not connected */  res = Curl_socket(conn, ai, &addr, &sockfd);  if(res)    /* Failed to create the socket, but still return OK since we signal the       lack of socket as well. This allows the parent function to keep looping       over alternative addresses/socket families etc. */    return CURLE_OK;  /* store remote address and port used in this connection attempt */  if(!getaddressinfo((struct sockaddr*)&addr.sa_addr,                     conn->primary_ip, &conn->primary_port)) {    /* malformed address or bug in inet_ntop, try next address */    error = ERRNO;    failf(data, "sa_addr inet_ntop() failed with errno %d: %s",          error, Curl_strerror(conn, error));    Curl_closesocket(conn, sockfd);    return CURLE_OK;  }  memcpy(conn->ip_addr_str, conn->primary_ip, MAX_IPADR_LEN);  infof(data, "  Trying %s.../n", conn->ip_addr_str);  Curl_persistconninfo(conn);  if(data->set.tcp_nodelay)    tcpnodelay(conn, sockfd);  nosigpipe(conn, sockfd);  Curl_sndbufset(sockfd);  if(data->set.tcp_keepalive)    tcpkeepalive(data, sockfd);  if(data->set.fsockopt) {    /* activate callback for setting socket options */    error = data->set.fsockopt(data->set.sockopt_client,                               sockfd,                               CURLSOCKTYPE_IPCXN);    if(error == CURL_SOCKOPT_ALREADY_CONNECTED)      isconnected = TRUE;    else if(error) {      Curl_closesocket(conn, sockfd); /* close the socket and bail out */      return CURLE_ABORTED_BY_CALLBACK;    }  }  /* possibly bind the local end to an IP, interface or port */  res = bindlocal(conn, sockfd, addr.family);  if(res) {    Curl_closesocket(conn, sockfd); /* close socket and bail out */    if(res == CURLE_UNSUPPORTED_PROTOCOL) {      /* The address family is not supported on this interface.         We can continue trying addresses */      return CURLE_OK;    }    return res;  }  /* set socket non-blocking */  curlx_nonblock(sockfd, TRUE);  conn->connecttime = Curl_tvnow();  if(conn->num_addr > 1)    Curl_expire(data, conn->timeoutms_per_addr);  /* Connect TCP sockets, bind UDP */  if(!isconnected && (conn->socktype == SOCK_STREAM)) {    rc = connect(sockfd, &addr.sa_addr, addr.addrlen);    if(-1 == rc)      error = SOCKERRNO;  }  else {    *sockp = sockfd;    return CURLE_OK;//.........这里部分代码省略.........
开发者ID:AlessioVallero,项目名称:RaspberryPI,代码行数:101,


示例21: file_do

/* * file_do() is the protocol-specific function for the do-phase, separated * from the connect-phase above. Other protocols merely setup the transfer in * the do-phase, to have it done in the main transfer loop but since some * platforms we support don't allow select()ing etc on file handles (as * opposed to sockets) we instead perform the whole do-operation in this * function. */static CURLcode file_do(struct connectdata *conn, bool *done){  /* This implementation ignores the host name in conformance with     RFC 1738. Only local files (reachable via the standard file system)     are supported. This means that files on remotely mounted directories     (via NFS, Samba, NT sharing) can be accessed through a file:// URL  */  CURLcode res = CURLE_OK;  struct_stat statbuf; /* struct_stat instead of struct stat just to allow the                          Windows version to have a different struct without                          having to redefine the simple word 'stat' */  curl_off_t expected_size=0;  bool fstated=FALSE;  ssize_t nread;  size_t bytestoread;  struct SessionHandle *data = conn->data;  char *buf = data->state.buffer;  curl_off_t bytecount = 0;  int fd;  struct timeval now = Curl_tvnow();  *done = TRUE; /* unconditionally */  Curl_initinfo(data);  Curl_pgrsStartNow(data);  if(data->set.upload)    return file_upload(conn);  /* get the fd from the connection phase */  fd = conn->data->state.proto.file->fd;  /* VMS: This only works reliable for STREAMLF files */  if( -1 != fstat(fd, &statbuf)) {    /* we could stat it, then read out the size */    expected_size = statbuf.st_size;    fstated = TRUE;  }  /* If we have selected NOBODY and HEADER, it means that we only want file     information. Which for FILE can't be much more than the file size and     date. */  if(data->set.opt_no_body && data->set.include_header && fstated) {    CURLcode result;    snprintf(buf, sizeof(data->state.buffer),             "Content-Length: %" FORMAT_OFF_T "/r/n", expected_size);    result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);    if(result)      return result;    result = Curl_client_write(conn, CLIENTWRITE_BOTH,                               (char *)"Accept-ranges: bytes/r/n", 0);    if(result)      return result;    if(fstated) {      const struct tm *tm;      time_t filetime = (time_t)statbuf.st_mtime;#ifdef HAVE_GMTIME_R      struct tm buffer;      tm = (const struct tm *)gmtime_r(&filetime, &buffer);#else      tm = gmtime(&filetime);#endif      /* format: "Tue, 15 Nov 1994 12:45:26 GMT" */      snprintf(buf, BUFSIZE-1,               "Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT/r/n",               Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],               tm->tm_mday,               Curl_month[tm->tm_mon],               tm->tm_year + 1900,               tm->tm_hour,               tm->tm_min,               tm->tm_sec);      result = Curl_client_write(conn, CLIENTWRITE_BOTH, buf, 0);    }    return result;  }  /* Check whether file range has been specified */  file_range(conn);  /* Adjust the start offset in case we want to get the N last bytes   * of the stream iff the filesize could be determined */  if(data->state.resume_from < 0) {    if(!fstated) {      failf(data, "Can't get the size of file.");      return CURLE_READ_ERROR;    }    else      data->state.resume_from += (curl_off_t)statbuf.st_size;  }//.........这里部分代码省略.........
开发者ID:RayPlante,项目名称:usvirtualobservatory,代码行数: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: smtp_done

/*********************************************************************** * * smtp_done() * * The DONE function. This does what needs to be done after a single DO has * performed. * * Input argument is already checked for validity. */static CURLcode smtp_done(struct connectdata *conn, CURLcode status,                          bool premature){  CURLcode result = CURLE_OK;  struct Curl_easy *data = conn->data;  struct SMTP *smtp = data->req.protop;  struct pingpong *pp = &conn->proto.smtpc.pp;  char *eob;  ssize_t len;  ssize_t bytes_written;  (void)premature;  if(!smtp || !pp->conn)    return CURLE_OK;  if(status) {    connclose(conn, "SMTP done with bad status"); /* marked for closure */    result = status;         /* use the already set error code */  }  else if(!data->set.connect_only && data->set.upload && data->set.mail_rcpt) {    /* Calculate the EOB taking into account any terminating CRLF from the       previous line of the email or the CRLF of the DATA command when there       is "no mail data". RFC-5321, sect. 4.1.1.4.       Note: As some SSL backends, such as OpenSSL, will cause Curl_write() to       fail when using a different pointer following a previous write, that       returned CURLE_AGAIN, we duplicate the EOB now rather than when the       bytes written doesn't equal len. */    if(smtp->trailing_crlf || !conn->data->state.infilesize) {      eob = strdup(SMTP_EOB + 2);      len = SMTP_EOB_LEN - 2;    }    else {      eob = strdup(SMTP_EOB);      len = SMTP_EOB_LEN;    }    if(!eob)      return CURLE_OUT_OF_MEMORY;    /* Send the end of block data */    result = Curl_write(conn, conn->writesockfd, eob, len, &bytes_written);    if(result) {      free(eob);      return result;    }    if(bytes_written != len) {      /* The whole chunk was not sent so keep it around and adjust the         pingpong structure accordingly */      pp->sendthis = eob;      pp->sendsize = len;      pp->sendleft = len - bytes_written;    }    else {      /* Successfully sent so adjust the response timeout relative to now */      pp->response = Curl_tvnow();      free(eob);    }    state(conn, SMTP_POSTDATA);    /* Run the state-machine       TODO: when the multi interface is used, this _really_ should be using       the smtp_multi_statemach function but we have no general support for       non-blocking DONE operations!    */    result = smtp_block_statemach(conn);  }  /* Cleanup our per-request based variables */  Curl_safefree(smtp->custom);  /* Clear the transfer mode for the next request */  smtp->transfer = FTPTRANSFER_BODY;  return result;}
开发者ID:hydnoracoin,项目名称:Open-Source-Cryptocurrency-Exchange,代码行数:90,


示例24: Curl_proxyCONNECT

//.........这里部分代码省略.........        if(CURLE_OK == result)          result = Curl_add_custom_headers(conn, req_buffer);        if(CURLE_OK == result)          /* CRLF terminate the request */          result = Curl_add_bufferf(req_buffer, "/r/n");        if(CURLE_OK == result) {          /* Send the connect request to the proxy */          /* BLOCKING */          result =            Curl_add_buffer_send(req_buffer, conn,                                 &data->info.request_size, 0, sockindex);        }        req_buffer = NULL;        if(result)          failf(data, "Failed sending CONNECT to proxy");      }      Curl_safefree(req_buffer);      if(result)        return result;      conn->bits.tunnel_connecting = TRUE;    } /* END CONNECT PHASE */    /* now we've issued the CONNECT and we're waiting to hear back -       we try not to block here in multi-mode because that might be a LONG       wait if the proxy cannot connect-through to the remote host. */    /* 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");      return CURLE_RECV_ERROR;    }    /* if we're in multi-mode and we would block, return instead for a retry */    if(Curl_if_multi == data->state.used_interface) {      if(0 == Curl_socket_ready(tunnelsocket, CURL_SOCKET_BAD, 0))        /* return so we'll be called again polling-style */        return CURLE_OK;      else {        DEBUGF(infof(data,                     "Multi mode finished polling for response from "                     "proxy CONNECT/n"));      }    }    else {      DEBUGF(infof(data, "Easy mode waiting response from proxy CONNECT/n"));    }    /* at this point, either:       1) we're in easy-mode and so it's okay to block waiting for a CONNECT       response       2) we're in multi-mode and we didn't block - it's either an error or we       now have some data waiting.       In any case, the tunnel_connecting phase is over. */    conn->bits.tunnel_connecting = FALSE;    { /* BEGIN NEGOTIATION PHASE */      size_t nread;   /* total size read */      int perline; /* count bytes per line */      int keepon=TRUE;
开发者ID:Tyf0n,项目名称:curl,代码行数:67,


示例25: Curl_output_digest

CURLcode Curl_output_digest(struct connectdata *conn,                            bool proxy,                            const unsigned char *request,                            const unsigned char *uripath){  /* We have a Digest setup for this, use it!  Now, to get all the details for     this sorted out, I must urge you dear friend to read up on the RFC2617     section 3.2.2, */  unsigned char md5buf[16]; /* 16 bytes/128 bits */  unsigned char request_digest[33];  unsigned char *md5this;  unsigned char *ha1;  unsigned char ha2[33];/* 32 digits and 1 zero byte */  char cnoncebuf[7];  char *cnonce = NULL;  size_t cnonce_sz = 0;  char *tmp = NULL;  struct timeval now;  char **allocuserpwd;  const char *userp;  const char *passwdp;  struct auth *authp;  struct SessionHandle *data = conn->data;  struct digestdata *d;  CURLcode rc;/* The CURL_OUTPUT_DIGEST_CONV macro below is for non-ASCII machines.   It converts digest text to ASCII so the MD5 will be correct for   what ultimately goes over the network.*/#define CURL_OUTPUT_DIGEST_CONV(a, b) /  rc = Curl_convert_to_network(a, (char *)b, strlen((const char*)b)); /  if(rc != CURLE_OK) { /    free(b); /    return rc; /  }  if(proxy) {    d = &data->state.proxydigest;    allocuserpwd = &conn->allocptr.proxyuserpwd;    userp = conn->proxyuser;    passwdp = conn->proxypasswd;    authp = &data->state.authproxy;  }  else {    d = &data->state.digest;    allocuserpwd = &conn->allocptr.userpwd;    userp = conn->user;    passwdp = conn->passwd;    authp = &data->state.authhost;  }  if(*allocuserpwd) {    Curl_safefree(*allocuserpwd);    *allocuserpwd = NULL;  }  /* not set means empty */  if(!userp)    userp="";  if(!passwdp)    passwdp="";  if(!d->nonce) {    authp->done = FALSE;    return CURLE_OK;  }  authp->done = TRUE;  if(!d->nc)    d->nc = 1;  if(!d->cnonce) {    /* Generate a cnonce */    now = Curl_tvnow();    snprintf(cnoncebuf, sizeof(cnoncebuf), "%06ld", (long)now.tv_sec);    rc = Curl_base64_encode(data, cnoncebuf, strlen(cnoncebuf),                            &cnonce, &cnonce_sz);    if(rc)      return rc;    d->cnonce = cnonce;  }  /*    if the algorithm is "MD5" or unspecified (which then defaults to MD5):    A1 = unq(username-value) ":" unq(realm-value) ":" passwd    if the algorithm is "MD5-sess" then:    A1 = H( unq(username-value) ":" unq(realm-value) ":" passwd )         ":" unq(nonce-value) ":" unq(cnonce-value)  */  md5this = (unsigned char *)    aprintf("%s:%s:%s", userp, d->realm, passwdp);  if(!md5this)//.........这里部分代码省略.........
开发者ID:karottc,项目名称:dtc_jd,代码行数:101,


示例26: 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;  int error = 0;  struct timeval now;  DEBUGASSERT(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);  *connected = FALSE; /* a very negative world view is best */  if(conn->bits.tcpconnect) {    /* we are connected already! */    *connected = TRUE;    return CURLE_OK;  }  now = Curl_tvnow();  /* 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 time-out");    return CURLE_OPERATION_TIMEDOUT;  }  /* check for connect without timeout as we want to return immediately */  rc = waitconnect(conn, sockfd, 0);  if(WAITCONN_TIMEOUT == rc) {    if(curlx_tvdiff(now, conn->connecttime) >= conn->timeoutms_per_addr) {      infof(data, "After %ldms connect time, move on!/n",            conn->timeoutms_per_addr);      goto next;    }    /* not an error, but also no connection yet */    return code;  }  if(WAITCONN_CONNECTED == rc) {    if(verifyconnect(sockfd, &error)) {      /* we are connected, awesome! */      conn->bits.tcpconnect = TRUE;      *connected = TRUE;      Curl_pgrsTime(data, TIMER_CONNECT); /* connect done */      Curl_verboseconnect(conn);      Curl_updateconninfo(conn, sockfd);      return CURLE_OK;    }    /* nope, not connected for real */  }  else {    /* nope, not connected  */    if(WAITCONN_FDSET_ERROR == rc) {      (void)verifyconnect(sockfd, &error);      infof(data, "%s/n",Curl_strerror(conn, error));    }    else      infof(data, "Connection failed/n");  }  /*   * 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);  }  next:  code = trynextip(conn, sockindex, connected);  if(code) {    error = SOCKERRNO;    data->state.os_errno = error;    failf(data, "Failed connect to %s:%ld; %s",          conn->host.name, conn->port, Curl_strerror(conn, error));  }  return code;}
开发者ID:AnthonyNystrom,项目名称:r17,代码行数:90,


示例27: 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:CSanshulgandhi,项目名称:rhodes,代码行数:89,


示例28: singleipconnect

//.........这里部分代码省略.........#endif  if(data->set.tcp_nodelay)    tcpnodelay(conn, sockfd);  nosigpipe(conn, sockfd);  Curl_sndbufset(sockfd);  if(data->set.fsockopt) {    /* activate callback for setting socket options */    error = data->set.fsockopt(data->set.sockopt_client,                               sockfd,                               CURLSOCKTYPE_IPCXN);    if(error) {      sclose(sockfd); /* close the socket and bail out */      return CURLE_ABORTED_BY_CALLBACK;    }  }  /* possibly bind the local end to an IP, interface or port */  res = bindlocal(conn, sockfd, addr.family);  if(res) {    sclose(sockfd); /* close socket and bail out */    return res;  }  /* set socket non-blocking */  curlx_nonblock(sockfd, TRUE);  /* Connect TCP sockets, bind UDP */  if(conn->socktype == SOCK_STREAM) {    rc = connect(sockfd, &addr.sa_addr, addr.addrlen);    conn->connecttime = Curl_tvnow();    if(conn->num_addr > 1)      Curl_expire(data, conn->timeoutms_per_addr);  }  else    rc = 0;  if(-1 == rc) {    error = SOCKERRNO;    switch (error) {    case EINPROGRESS:    case EWOULDBLOCK:#if defined(EAGAIN)#if (EAGAIN) != (EWOULDBLOCK)      /* On some platforms EAGAIN and EWOULDBLOCK are the       * same value, and on others they are different, hence       * the odd #if       */    case EAGAIN:#endif#endif      rc = waitconnect(conn, sockfd, timeout_ms);      if(WAITCONN_ABORTED == rc) {        sclose(sockfd);        return CURLE_ABORTED_BY_CALLBACK;      }      break;    default:      /* unknown error, fallthrough and try another address! */      failf(data, "Failed to connect to %s: %s",            conn->ip_addr_str, Curl_strerror(conn,error));      data->state.os_errno = error;
开发者ID:AnthonyNystrom,项目名称:r17,代码行数:67,


示例29: 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:crawlik,项目名称:curl,代码行数:101,


示例30: Curl_sftp_do

//.........这里部分代码省略.........            char linkPath[PATH_MAX + 1];            snprintf(linkPath, PATH_MAX, "%s%s", sftp->path, filename);            len = libssh2_sftp_readlink(sftp->sftp_session, linkPath, filename,                                        PATH_MAX);            line = realloc(line, totalLen + 4 + len);            if (!line)              return CURLE_OUT_OF_MEMORY;            currLen += snprintf(line+currLen, totalLen-currLen, " -> %s",                                filename);          }          currLen += snprintf(line+currLen, totalLen-currLen, "/n");          res = Curl_client_write(conn, CLIENTWRITE_BODY, line, 0);          free(line);        }      }      libssh2_sftp_closedir(sftp->sftp_handle);      sftp->sftp_handle = NULL;      /* no data to transfer */      res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);    }    else {      /*       * Work on getting the specified file       */      sftp->sftp_handle =        libssh2_sftp_open(sftp->sftp_session, sftp->path, LIBSSH2_FXF_READ,                          LIBSSH2_SFTP_S_IRUSR|LIBSSH2_SFTP_S_IWUSR|                          LIBSSH2_SFTP_S_IRGRP|LIBSSH2_SFTP_S_IROTH);      if (!sftp->sftp_handle)        return CURLE_SSH;      if (libssh2_sftp_stat(sftp->sftp_session, sftp->path, &attrs)) {        /*         * libssh2_sftp_open() didn't return an error, so maybe the server         * just doesn't support stat()         */        data->reqdata.size = -1;        data->reqdata.maxdownload = -1;      }      else {        data->reqdata.size = attrs.filesize;        data->reqdata.maxdownload = attrs.filesize;        Curl_pgrsSetDownloadSize(data, attrs.filesize);      }      Curl_pgrsTime(data, TIMER_STARTTRANSFER);      /* Now download data. The libssh2 0.14 doesn't offer any way to do this         without using this BLOCKING approach, so here's room for improvement         once libssh2 can return EWOULDBLOCK to us. */#if 0      /* code left here just because this is what this function will use the         day libssh2 is improved */      res = Curl_setup_transfer(conn, FIRSTSOCKET,                                bytecount, FALSE, NULL, -1, NULL);#endif      while (res == CURLE_OK) {        size_t nread;        /* NOTE: most *read() functions return ssize_t but this returns size_t           which normally is unsigned! */        nread = libssh2_sftp_read(data->reqdata.proto.ssh->sftp_handle,                                  buf, BUFSIZE-1);        if (nread > 0)          buf[nread] = 0;        /* this check can be changed to a <= 0 when nread is changed to a           signed variable type */        if ((nread == 0) || (nread == (size_t)~0))          break;        bytecount += nread;        res = Curl_client_write(conn, CLIENTWRITE_BODY, buf, nread);        if(res)          return res;        Curl_pgrsSetDownloadCounter(data, bytecount);        if(Curl_pgrsUpdate(conn))          res = CURLE_ABORTED_BY_CALLBACK;        else {          struct timeval now = Curl_tvnow();          res = Curl_speedcheck(data, now);        }      }      if(Curl_pgrsUpdate(conn))        res = CURLE_ABORTED_BY_CALLBACK;      /* no (more) data to transfer */      res = Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL);    }  }  return res;}
开发者ID:Multi2Sim,项目名称:m2s-bench-parsec-3.0-src,代码行数:101,



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


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