libcurl-http发送数据流程

源码目录

docs/example/httpcustomheader.c  添加自定义headers

 http-post.c  按字符串推送数据

simplepost.c 按长度推送数据

httpput.c  按文件推送

 

curl_easy_perform()

easy_transfer()

curl_multi_perform()

multi_runsingle()

 

CURLM_STATE_CONNECT

 

Curl_connect() (url.c)

create_conn()

  conn = allocate_conn(data);

  

  conn->recv[FIRSTSOCKET] = Curl_recv_plain;     //默认发送接收数据
  conn->send[FIRSTSOCKET] = Curl_send_plain;
  conn->recv[SECONDARYSOCKET] = Curl_recv_plain;
  conn->send[SECONDARYSOCKET] = Curl_send_plain;

 

  parseurlandfillconn()

  findprotocol()

    struct Curl_handler *p = Curl_builtin_scheme(protostr);

    conn->handler = conn->given = p;  

 

    Curl_builtin_scheme() (url.c)

      取出对应协议Curl_handler,包括连接,发送,接收处理等

      static const struct Curl_handler * const protocols[] = {

      #ifndef CURL_DISABLE_HTTP
      &Curl_handler_http,
      #endif

      #if defined(USE_SSL) && !defined(CURL_DISABLE_HTTP)
      &Curl_handler_https,
      #endif

 

 

CURLM_STATE_DO

multi_do()

  conn->handler->do_it(conn, done);

  Curl_http() (http.c)

 

  Curl_add_bufferf(&req_buffer,   //http 头数据发送
  "%s" /* ftp typecode (;type=x) */
  " HTTP/%s\r\n" /* HTTP version */

 

  Curl_add_custom_headers()   //添加自定义http头数据

 

  if(data->set.postfields) {  //按chunk,数据长度,文件推送数据

   Curl_add_buffer_send() //发送数据

     Curl_write()

      conn->send[] -> Curl_send_plain()

       *written = bytes_written; //保存已发送的数据

 

 

上一篇:解决图片上传的浏览器兼容问题


下一篇:python 安装ss(转)