curl / Mailing Lists / curl-users / Single Mail

curl-users

An error when I used the multi curl API to do POST and GET in parallel

From: 杨俊 <yangjun9772_at_gmail.com>
Date: Tue, 3 Jan 2017 18:21:48 +0800

Hi guys,

I have a problem in code now.
*What I want is that*:
1. I will do GET to the server and wait for the response, it maybe waiting
for a long time.
2. I will do GET as a "Ping" to the server with another url for every 5 min.
3. I will do some POST to the server with another url as the command(it
will upload a audio file). In my mind, I think that maybe I can use the
"Ping" and the POST in one curl_handle, use the GET of waiting for response
in another curl_handle by multi API.
*So I do three test:*
1. I create two curl_handles, one for "Ping", the other for GET. This works
well. Every 5 min it will send the "Ping" again and the other handle is
waiting for the response. And the "Ping" can re-use.
2. Creating 2 curl_handles, one for POST, the other for GET. It seems work
well too, I input a command to POST again and again, this can work, but
seems no re-use.
3. Creating 2 curl_handles, one for POST and "ping", one for GET. It
couldn't work well now. In my code, first I send the PING and GET. And the
server can return the result. In this time, GET is still waiting and the
PING is finished. Then I input a command to let the curl_handle of "PING"
change to POST's configuration to do POST, but the error is occurred. The
POST can't send the file(a audio file).
*My question is:*
If I use the curl in a wrong way?
Can I use the PING and POST in the same curl_handle and re-use it?
Please give me some suggestion.
I used the libcurl7.51.0

*This is my code:*
----------------------------------for test 3/ test2 test1 almost the same
----------------
#define HANDLECOUNT 2
#define DOWN_HANDLE 0
#define UP_HANDLE 1

size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
printf("write data begin...\n");
    int written = fwrite(ptr, size, nmemb, (FILE *)stream);
    fflush((FILE *)stream);
    return written;
}
size_t readFileFunc(char *buffer, size_t size, size_t nitems, void
*instream)
{
printf("begin freadfunc ... \n");
int readSize = fread( buffer, size, nitems, (FILE *)instream );

return readSize;
}

static void curl_send_audio_cfg(CURL *curl, struct curl_slist *head,char
*auth, char *strJSONout,
                                                struct curl_httppost
*postFirst,struct curl_httppost *postLast,
                                                FILE *saveHeadFile, FILE
*saveBodyFile, FILE *uploadFile)
{
CURLcode res;
cJSON *root, *context, *event, *header, *payload, *nonname, *tmpJson;
long uploadFileSize = 0;
/* set the opt */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0 );
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_CAINFO, "/tmp/cacert.pem");
/* set the head */
head = curl_slist_append(head , DEL_HTTPHEAD_EXPECT);
head = curl_slist_append(head , DEL_HTTPHEAD_ACCEPT);
head = curl_slist_append(head , "Path: /v20160207/events");
head = curl_slist_append(head , auth);
head = curl_slist_append(head , "Content-type: multipart/form-data" );
head = curl_slist_append(head , "Transfer-Encoding: chunked");
head = curl_slist_append(head , "Host: avs-alexa-na.amazon.com");

/* set the json */
root=cJSON_CreateObject();
cJSON_AddItemToObject(root, "context", context = cJSON_CreateArray() );

//========Events===========//
cJSON_AddItemToObject(root, "event", event = cJSON_CreateObject());

//===========Tail===============//
strJSONout = cJSON_Print(root);
cJSON_Delete(root);

/* formadd */
uploadFileSize = ftell( uploadFile );

//============josn================//
curl_formadd(&postFirst, &postLast,
CURLFORM_COPYNAME, "metadata",
CURLFORM_COPYCONTENTS, strJSONout,
CURLFORM_CONTENTTYPE, "application/json; charset=UTF-8",
CURLFORM_END);

//=============Audio=================//
curl_formadd(&postFirst, &postLast,
CURLFORM_COPYNAME, "audio",
//CURLFORM_CONTENTHEADER, contentAudioHeaderSlist,
CURLFORM_STREAM, uploadFile,
CURLFORM_CONTENTSLENGTH, uploadFileSize,
CURLFORM_CONTENTTYPE, "application/octet-stream",
CURLFORM_END);

/* set the url */
curl_easy_setopt(curl, CURLOPT_URL, "
https://avs-alexa-na.amazon.com/v20160207/events");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, head);

curl_easy_setopt(curl, CURLOPT_READFUNCTION, readFileFunc);
curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, write_data );
curl_easy_setopt(curl, CURLOPT_HEADERDATA, saveHeadFile );
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data );
curl_easy_setopt(curl, CURLOPT_WRITEDATA, saveBodyFile );

/* set http post */
// curl_easy_setopt(curl, CURLOPT_HTTPGET, 0L);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, postFirst);

}

static void curl_ping_cfg(CURL *curl, struct curl_slist *head, char *auth)
{
CURLcode res;

/* set the opt */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0 );
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_CAINFO, "/tmp/cacert.pem");

/* set the head */
head = curl_slist_append(head , DEL_HTTPHEAD_ACCEPT);
head = curl_slist_append(head , "Path: /ping");
head = curl_slist_append(head , auth);
head = curl_slist_append(head , "Host: avs-alexa-na.amazon.com");
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, head);
if (res != CURLE_OK){
printf("%s: curl_easy_setopt failed: %s\n",
__FUNCTION__,curl_easy_strerror(res));
}

/* set the url */
curl_easy_setopt(curl, CURLOPT_URL, "https://avs-alexa-na.amazon.com/ping");

/* set the GET */
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);

}

static void curl_downchannel_cfg(CURL *curl, struct curl_slist *head, char
*auth)
{
CURLcode res;

/* set the opt */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2_0);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
curl_easy_setopt(curl, CURLOPT_CAINFO, "/tmp/cacert.pem");

/* set the head */
head = curl_slist_append(head , DEL_HTTPHEAD_ACCEPT);
head = curl_slist_append(head , "Path: /v20160207/directives");
head = curl_slist_append(head , auth);
head = curl_slist_append(head , "Host: avs-alexa-na.amazon.com");
res = curl_easy_setopt(curl, CURLOPT_HTTPHEADER, head);
if (res != CURLE_OK){
printf("%s: curl_easy_setopt failed: %s\n",
__FUNCTION__,curl_easy_strerror(res));
}

/* set the url */
curl_easy_setopt(curl, CURLOPT_URL, "
https://avs-alexa-na.amazon.com/v20160207/directives");

}

void thread_task2(void)
{
int ret = 0;
CURL *handles[HANDLECOUNT];
CURLM *multi_handle;
int i;
int still_running; /* keep number of running handles */
CURLMsg *msg; /* for picking up messages with the transfer status */
int msgs_left; /* how many messages are left */
char Authorization[1024] = "Authorization:Bearer ";
/* for the event */
char *strJSONout = NULL;
struct curl_httppost *postFirst = NULL, *postLast = NULL;
FILE *saveHeadFile = NULL, *saveBodyFile = NULL, *uploadFile = NULL;

struct curl_slist *downHeader = NULL;
struct curl_slist *upHead = NULL;
CURLcode res;

strcat( Authorization, atoken );
printf( "%s\nstarting ...\n", Authorization );

/* init a multi stack */
multi_handle = curl_multi_init();
/* Allocate one CURL handle per transfer */
for(i=0; i<HANDLECOUNT; i++){
handles[i] = curl_easy_init();
curl_multi_add_handle(multi_handle, handles[i]);
}
/* set the downchannel opt */

curl_downchannel_cfg(handles[DOWN_HANDLE], downHeader, Authorization);

/* set the ping opt */

// curl_ping_cfg(handles[UP_HANDLE], upHead, Authorization);
// pingState = 1;

/* set the event opt */
saveHeadFile = fopen( HEAD_FILE_NAME, "w+" );
saveBodyFile = fopen( BODY_FILE_NAME, "w+" );
uploadFile = fopen( UPLOAD_FILE_NAME, "rb" );
curl_send_audio_cfg(handles[UP_HANDLE], upHead, Authorization, strJSONout,
postFirst, postLast, saveHeadFile, saveBodyFile, uploadFile);
eventState = 1;
/* run */
// curl_multi_setopt(multi_handle, CURLMOPT_PIPELINING, CURLPIPE_MULTIPLEX);
/* We do HTTP/2 so let's stick to one connection per host */
// curl_multi_setopt(multi_handle, CURLMOPT_MAX_HOST_CONNECTIONS, 1L);
/* we start some action by calling perform right away */
curl_multi_perform(multi_handle, &still_running);

do {
struct timeval timeout;
int rc;/* select() return code */
CURLMcode mc; /* curl_multi_fdset() return code */

fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;

long curl_timeo = -1;
/* ping flag */
if (pingFlag){
pingFlag = 0;
pingState = 1;
printf("start ping ~~~~~~~~~~~\n");
curl_ping_cfg(handles[UP_HANDLE], upHead, Authorization);
curl_multi_add_handle(multi_handle, handles[UP_HANDLE]);
} else {
if (sendToAlexaFlag){
sendToAlexaFlag = 0;
eventState = 1;
saveHeadFile = fopen( HEAD_FILE_NAME, "w+" );
saveBodyFile = fopen( BODY_FILE_NAME, "w+" );
uploadFile = fopen( UPLOAD_FILE_NAME, "rb" );
curl_send_audio_cfg(handles[UP_HANDLE], upHead, Authorization,
strJSONout, postFirst, postLast,
saveHeadFile, saveBodyFile, uploadFile);
curl_multi_add_handle(multi_handle, handles[UP_HANDLE]);
}

}
/* set the multi_curl_handle */
FD_ZERO(&fdread);
FD_ZERO(&fdwrite);
FD_ZERO(&fdexcep);

/* set a suitable timeout to play around with */
timeout.tv_sec = 1;
timeout.tv_usec = 0;

curl_multi_timeout(multi_handle, &curl_timeo);
if(curl_timeo >= 0) {
timeout.tv_sec = curl_timeo / 1000;
if(timeout.tv_sec > 1)
timeout.tv_sec = 1;
else
timeout.tv_usec = (curl_timeo % 1000) * 1000;
}

/* get file descriptors from the transfers */
mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);

if(mc != CURLM_OK) {
fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);
break;
}
/* On success the value of maxfd is guaranteed to be >= -1. We call
select(maxfd + 1, ...); specially in case of (maxfd == -1) there are
no fds ready yet so we call select(0, ...) --or Sleep() on Windows--
to sleep 100ms, which is the minimum suggested value in the
curl_multi_fdset() doc. */
if(maxfd == -1) {
/* Portable sleep for platforms other than Windows. */
struct timeval wait = { 0, 100 * 1000 }; /* 100ms */
rc = select(0, NULL, NULL, NULL, &wait);
}
else {
/* Note that on some platforms 'timeout' may be modified by select().
If you need access to the original value save a copy beforehand. */
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
}
switch(rc) {
case -1:
/* select error */
printf("~~~~~this is error~~~\n");
break;
case 0:
default:
/* timeout or readable/writable sockets */
curl_multi_perform(multi_handle, &still_running);
break;
}

/* See how the transfers went */
while((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
if(msg->msg == CURLMSG_DONE) {
int idx, found = 0;

/* Find out which handle this message is about */
for(idx=0; idx<HANDLECOUNT; idx++) {
found = (msg->easy_handle == handles[idx]);
if(found)
break;
}

switch(idx) {
case DOWN_HANDLE:
printf("Downstream completed with status %d\n", msg->data.result);
break;
case UP_HANDLE:
if (pingState){
pingState = 0;
printf("ping completed with status %d\n", msg->data.result);
}
if (eventState){
eventState = 0;
printf("event completed with status %d\n", msg->data.result);
free(strJSONout);
fclose(uploadFile);
fclose(saveBodyFile);
fclose(saveHeadFile);
curl_formfree( postFirst);
}
/* after send the ping, then remove the handle */
curl_multi_remove_handle(multi_handle , handles[UP_HANDLE]);
break;
}
}
}

} while(still_running);

/* clean up */
curl_multi_cleanup(multi_handle);
/* Free the CURL handles */
for(i=0; i<HANDLECOUNT; i++)
curl_easy_cleanup(handles[i]);

/* free the custom headers */
curl_slist_free_all(downHeader);
curl_slist_free_all(upHead);

}

----------------------------------------------------------------------------------------end

*The log:*
*----------for test 1--------------------------*
[10:27:35]/tmp # ./test_alexa_device 1
[10:27:35]---------3-------
[10:27:35]please input enter to start talking...
[10:27:35]starting ...
[10:27:40]* Trying 54.239.21.157...
[10:27:40]* TCP_NODELAY set
[10:27:40]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931ee0
[serially]
[10:27:40]* Server doesn't support multi-use (yet)
[10:27:40]* No more connections allowed to host: 1
[10:27:40]* No connections available.
[10:27:40]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#0)
[10:27:40]* ALPN, offering h2
[10:27:40]* ALPN, offering http/1.1
[10:27:40]* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
[10:27:41]* successfully set certificate verify locations:
[10:27:41]* CAfile: /tmp/cacert.pem
[10:27:41] CApath: none
[10:27:41]* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
[10:27:41]* ALPN, server accepted to use h2
[10:27:41]* Server certificate:
[10:27:41]* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.;
CN=latinum.amazon.com
[10:27:41]* start date: Sep 22 00:00:00 2016 GMT
[10:27:41]* expire date: Oct 16 23:59:59 2017 GMT
[10:27:41]* subjectAltName: host "avs-alexa-na.amazon.com" matched cert's "
avs-alexa-na.amazon.com"
[10:27:41]* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust
Network; CN=Symantec Class 3 Secure Server CA - G4
[10:27:41]* SSL certificate verify ok.
[10:27:41]* Using HTTP2, server supports multi-use
[10:27:41]* Connection state changed (HTTP/2 confirmed)
[10:27:41]* Copying HTTP/2 data in stream buffer to connection buffer after
upgrade: len=0
[10:27:41]* Using Stream ID: 1 (easy handle 0xb591fca8)
*[10:27:41]> GET /v20160207/directives HTTP/1.1*
[10:27:41]Host: avs-alexa-na.amazon.com
[10:27:41]Path: /v20160207/directives
[10:27:41]
[10:27:41]* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
[10:27:41]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931ee0 [can
multiplex]
[10:27:41]* Conn: 0 (0xb5931670) Receive pipe weight: (-1/0), penalized:
(nil)
[10:27:41]* Multiplexed connection found!
[10:27:41]* Found connection 0, with requests in the pipe (1)
[10:27:41]* Re-using existing connection! (#0) with host
avs-alexa-na.amazon.com
[10:27:41]* Using Stream ID: 3 (easy handle 0xb5928558)
*[10:27:41]> GET /ping HTTP/1.1*
[10:27:41]Host: avs-alexa-na.amazon.com
[10:27:41]Path: /ping
[10:27:41]
[10:27:42]< HTTP/2 200
[10:27:42]<
[10:27:42]< HTTP/2 204
[10:27:42]<
[10:27:42]* Curl_http_done: called premature == 0
[10:27:42]Ping completed with status 0
[10:28:05]send the heartbeat------
[10:28:06]start ping ~~~~~~~~~~~
[10:28:06]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931ee0 [can
multiplex]
[10:28:06]* Conn: 0 (0xb5931670) Receive pipe weight: (-1/0), penalized:
(nil)
[10:28:06]* Multiplexed connection found!
[10:28:06]* Found connection 0, with requests in the pipe (1)
[10:28:06]* *Re-using* existing connection! (#0) with host
avs-alexa-na.amazon.com //-----------*re-use and ping
again*
[10:28:06]* Using Stream ID: 5 (easy handle 0xb5928558)
*[10:28:06]> GET /ping HTTP/1.1*
[10:28:06]Host: avs-alexa-na.amazon.com
[10:28:06]Path: /ping
[10:28:06]
[10:28:06]< HTTP/2 204
[10:28:06]<
[10:28:06]* Curl_http_done: called premature == 0
[10:28:06]Ping completed with status 0
[10:28:35]send the heartbeat------

---------------------------------------------------------------------------end
*-------------------------log for test
2-------------------------------------------*
[16:53:52]/tmp # ./test_alexa_device 1
[16:53:52]---------5-------
[16:53:52]please input enter to start talking...
[16:53:52]starting ...
[16:53:52]288
[16:53:52]uploadFileSize = 64000
[16:53:52]* Trying 54.239.21.157...
[16:53:52]* TCP_NODELAY set
[16:53:52]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931bd8
[serially]
[16:53:52]* Hostname avs-alexa-na.amazon.com was found in DNS cache
[16:53:52]* Trying 54.239.21.157...
[16:53:52]* TCP_NODELAY set
[16:53:52]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#1)
[16:53:52]* ALPN, offering h2
[16:53:52]* ALPN, offering http/1.1
[16:53:52]* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
[16:53:52]* successfully set certificate verify locations:
[16:53:52]* CAfile: /tmp/cacert.pem
[16:53:52] CApath: none
[16:53:52]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#0)
[16:53:52]* ALPN, offering h2
[16:53:52]* ALPN, offering http/1.1
[16:53:52]* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
[16:53:52]* successfully set certificate verify locations:
[16:53:52]* CAfile: /tmp/cacert.pem
[16:53:52] CApath: none
[16:53:53]* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
[16:53:53]* ALPN, server accepted to use h2
[16:53:53]* Server certificate:
[16:53:53]* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.;
CN=latinum.amazon.com
[16:53:53]* start date: Sep 22 00:00:00 2016 GMT
[16:53:53]* expire date: Oct 16 23:59:59 2017 GMT
[16:53:53]* subjectAltName: host "avs-alexa-na.amazon.com" matched cert's "
avs-alexa-na.amazon.com"
[16:53:53]* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust
Network; CN=Symantec Class 3 Secure Server CA - G4
[16:53:53]* SSL certificate verify ok.
[16:53:53]* Using HTTP2, server supports multi-use
[16:53:53]* Connection state changed (HTTP/2 confirmed)
[16:53:53]* Copying HTTP/2 data in stream buffer to connection buffer after
upgrade: len=0
[16:53:53]* Using Stream ID: 1 (easy handle 0xb5928558)
[16:53:53]*> POST /v20160207/events HTTP/1.1*
[16:53:53]Host: avs-alexa-na.amazon.com
[16:53:53]Path: /v20160207/events
[16:53:53]Content-type: multipart/form-data;
boundary=------------------------4180e79e9de18c2b
[16:53:53]
[16:53:53]* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
[16:53:53*]begin freadfunc ...*

 //------------------------------*can read the file*
[16:53:53]* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
[16:53:53]* ALPN, server accepted to use h2
[16:53:53]* Server certificate:
[16:53:53]* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.;
CN=latinum.amazon.com
[16:53:53]* start date: Sep 22 00:00:00 2016 GMT
[16:53:53]* expire date: Oct 16 23:59:59 2017 GMT
[16:53:53]* subjectAltName: host "avs-alexa-na.amazon.com" matched cert's "
avs-alexa-na.amazon.com"
[16:53:53]* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust
Network; CN=Symantec Class 3 Secure Server CA - G4
[16:53:53]* SSL certificate verify ok.
[16:53:53]* Using HTTP2, server supports multi-use
[16:53:53]* Connection state changed (HTTP/2 confirmed)
[16:53:53]* Copying HTTP/2 data in stream buffer to connection buffer after
upgrade: len=0
[16:53:53]* Using Stream ID: 1 (easy handle 0xb591fca8)
[16:53:53]*> GET /v20160207/directives HTTP/1.1*
[16:53:53]Host: avs-alexa-na.amazon.com
[16:53:53]Path: /v20160207/directives
[16:53:53]* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
[16:53:53]begin freadfunc ...
[16:53:53]begin freadfunc ...
[16:53:54]begin freadfunc ...
[16:53:54]begin freadfunc ...
[16:53:54]< HTTP/2 200
[16:53:54]<
[16:53:56]< HTTP/2 200
[16:53:56]write data begin...
[16:53:56]<
[16:53:56]write data begin...
[16:53:56]* Curl_http_done: called premature == 0
[16:53:56]* Connection #1 to host avs-alexa-na.amazon.com left intact
[16:53:56]event completed with status 0
             //----------------------*-ok*
[16:54:04]
[16:54:04]please input enter to stop talking...
[16:54:04]please input enter to start talking...
[16:54:04]288
[16:54:04]uploadFileSize = 64000
[16:54:04]* Connection 1 seems to be dead!
[16:54:04]* Closing connection 1
[16:54:04]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931bd8 [can
multiplex]
[16:54:04]* Hostname avs-alexa-na.amazon.com was found in DNS cache
[16:54:04]* Trying 54.239.21.157...
[16:54:04]* TCP_NODELAY set
[16:54:04]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#2)
[16:54:04]* ALPN, offering h2
[16:54:04]* ALPN, offering http/1.1
[16:54:04]* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
[16:54:04]* successfully set certificate verify locations:
[16:54:04]* CAfile: /tmp/cacert.pem
[16:54:04] CApath: none
[16:54:04]* SSL re-using session ID
[16:54:05]* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
[16:54:05]* ALPN, server accepted to use h2
[16:54:05]* old SSL session ID is stale, removing
[16:54:05]* Server certificate:
[16:54:05]* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.;
CN=latinum.amazon.com
[16:54:05]* start date: Sep 22 00:00:00 2016 GMT
[16:54:05]* expire date: Oct 16 23:59:59 2017 GMT
[16:54:05]* subjectAltName: host "avs-alexa-na.amazon.com" matched cert's "
avs-alexa-na.amazon.com"
[16:54:05]* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust
Network; CN=Symantec Class 3 Secure Server CA - G4
[16:54:05]* SSL certificate verify ok.
*[16:54:05]* Using HTTP2, server supports multi-use*
[16:54:05]* Connection state changed (HTTP/2 confirmed)
[16:54:05]* Copying HTTP/2 data in stream buffer to connection buffer after
upgrade: len=0
[16:54:05]* Using Stream ID: 1 (easy handle 0xb5928558)
[16:54:05]>* POST /v20160207/events HTTP/1.1
          //----------------------can POST again but no re-use?*
[16:54:05]Host: avs-alexa-na.amazon.com
[16:54:05]Path: /v20160207/events
*[16:54:05]begin freadfunc ... *
[16:54:05]begin freadfunc ...
[16:54:05]begin freadfunc ...
[16:54:05]begin freadfunc ...
[16:54:05]begin freadfunc ...
[16:54:07]< HTTP/2 200
[16:54:07]write data begin...
[16:54:07]< access-control-allow-origin: *
[16:54:07]write data begin...
[16:54:07]<
[16:54:08]write data begin...
[16:54:08]* Curl_http_done: called premature == 0
[16:54:08]* Connection #2 to host avs-alexa-na.amazon.com left intact
[16:54:08]event completed with status 0
       //-------------------------ok
[16:54:15]
----------------------------------------------------------end
*----------------------------------------------------log for test 3
 error--------------------------------------*
[16:48:04]/tmp # ./test_alexa_device 1
[16:48:04]---------5-------
[16:48:04]starting ...
[16:48:04]* Trying 54.239.21.157...
[16:48:04]* TCP_NODELAY set
[16:48:04]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931ee0
[serially]
[16:48:04]* Hostname avs-alexa-na.amazon.com was found in DNS cache
[16:48:04]* Trying 54.239.21.157...
[16:48:04]* TCP_NODELAY set
[16:48:04]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#1)
[16:48:04]* ALPN, offering h2
[16:48:04]* ALPN, offering http/1.1
[16:48:04]* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
[16:48:05]* successfully set certificate verify locations:
[16:48:05]* CAfile: /tmp/cacert.pem
[16:48:05] CApath: none
[16:48:05]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#0)
[16:48:05]* ALPN, offering h2
[16:48:05]* ALPN, offering http/1.1
[16:48:05]* Cipher selection:
ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
[16:48:05]* successfully set certificate verify locations:
[16:48:05]* CAfile: /tmp/cacert.pem
[16:48:05] CApath: none
[16:48:05]* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
[16:48:05]* ALPN, server accepted to use h2
[16:48:05]* Server certificate:
[16:48:05]* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.;
CN=latinum.amazon.com
[16:48:05]* start date: Sep 22 00:00:00 2016 GMT
[16:48:05]* expire date: Oct 16 23:59:59 2017 GMT
[16:48:05]* subjectAltName: host "avs-alexa-na.amazon.com" matched cert's "
avs-alexa-na.amazon.com"
[16:48:05]* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust
Network; CN=Symantec Class 3 Secure Server CA - G4
[16:48:05]* SSL certificate verify ok.
[16:48:05]* Using HTTP2, server supports multi-use
[16:48:05]* Connection state changed (HTTP/2 confirmed)
[16:48:05]* Copying HTTP/2 data in stream buffer to connection buffer after
upgrade: len=0
[16:48:05]* Using Stream ID: 1 (easy handle 0xb5928558)
[16:48:05]*> GET /ping HTTP/1.1
//-------------------------------------------ping------------------------------*
[16:48:05]Host: avs-alexa-na.amazon.com
[16:48:05]Path: /ping
[16:48:05]
[16:48:05]* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
[16:48:05]* SSL connection using TLSv1.2 / ECDHE-RSA-AES256-GCM-SHA384
[16:48:05]* ALPN, server accepted to use h2
[16:48:05]* Server certificate:
[16:48:06]* subject: C=US; ST=Washington; L=Seattle; O=Amazon.com, Inc.;
CN=latinum.amazon.com
[16:48:06]* start date: Sep 22 00:00:00 2016 GMT
[16:48:06]* expire date: Oct 16 23:59:59 2017 GMT
[16:48:06]* subjectAltName: host "avs-alexa-na.amazon.com" matched cert's "
avs-alexa-na.amazon.com"
[16:48:06]* issuer: C=US; O=Symantec Corporation; OU=Symantec Trust
Network; CN=Symantec Class 3 Secure Server CA - G4
[16:48:06]* SSL certificate verify ok.
[16:48:06]* Using HTTP2, server supports multi-use
[16:48:06]* Connection state changed (HTTP/2 confirmed)
[16:48:06]* Copying HTTP/2 data in stream buffer to connection buffer after
upgrade: len=0
[16:48:06]* Using Stream ID: 1 (easy handle 0xb591fca8)
[16:48:06]*> GET /v20160207/directives HTTP/1.1
 //--------------------------get------------------------------*
[16:48:06]Host: avs-alexa-na.amazon.com
[16:48:06]Path: /v20160207/directives
[16:48:06]
[16:48:06]* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
[16:48:06]< HTTP/2 204
[16:48:06]<
[16:48:06]* Curl_http_done: called premature == 0
[16:48:06]* Connection #1 to host avs-alexa-na.amazon.com left intact
[16:48:06]ping completed with status 0
[16:48:06]< HTTP/2 200
[16:48:06]<
[16:48:13]
[16:48:13]please input enter to stop talking...
[16:48:13]please input enter to start talking...
[16:48:14]288
[16:48:14]uploadFileSize = 64000
[16:48:14]* Found bundle for host avs-alexa-na.amazon.com: 0xb5931ee0 [can
multiplex]
[16:48:14]* Re-using existing connection! (#1) with host
avs-alexa-na.amazon.com
[16:48:14]* Connected to avs-alexa-na.amazon.com (54.239.21.157) port 443
(#1)
[16:48:14]* Using Stream ID: 3 (easy handle 0xb5928558)
[16:48:14]*> POST /v20160207/events HTTP/1.1
//--------------------------------------------POST-----------------*
[16:48:14]Host: avs-alexa-na.amazon.com
[16:48:14]Path: /v20160207/events
[16:48:14]
[16:48:24]*< HTTP/2 400 //------------------------error,
can't read the file---------------------------------*
[16:48:24]write data begin...
[16:48:24]< access-control-allow-origin: *
--------------------------------------------------------------------------------end

-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-users
FAQ: https://curl.haxx.se/docs/faq.html
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2017-01-03