Http failed the second time


#1

good afternoon everybody.

Could you help me for a little problem. i’m trying to send a http get request to a http server. The first time i send the request, i correctly have my answer but the second time, i have a WIP_CERR_ABORTED error. if i try to send my request a third time i have my answer. it works one time on two. Here is a part of my code.

// =========================================================================
//	CLASSE	:
//	METHODE	: httpGetDataHandler
// =========================================================================
void httpDataHandler( wip_event_t *ev, void *ctx)
{
	char tmpbuff[256];

	switch( ev->kind)
	{
		case WIP_CEV_READ:
		{
			usr_printf( 1, "WIP_CEV_READ\r\n");
			int len = 0;
			while(( len = wip_read( ev->channel, tmpbuff, sizeof( tmpbuff) - 1)) > 0)
			{
				//TODO: remplacer par envoi uart2
				tmpbuff[len] = 0;
				usr_printf( 1, "%s", tmpbuff);
			}
			usr_printf( 1, "\r\n");
		}
		break;
		case WIP_CEV_WRITE:
		{
			usr_printf( 1, "WIP_CEV_WRITE\r\n");
			//TODO: remplacer par reception uart2
			DWORD offset = (( tHttpClientCtx *)ctx)->dataLength;
			while( offset)
			{
				int WrittenBytes;
				WrittenBytes = wip_write( ev->channel,
										  tabImgTest + (( tHttpClientCtx *)ctx)->dataLength - offset,
										  offset);
				_ASSERT( WrittenBytes > 0);
				offset -= ( WrittenBytes);
			}
		}
		break;
		case WIP_CEV_PEER_CLOSE:
		{
			usr_printf( 1, "WIP_CEV_PEER_CLOSE\r\n");
			int ret = 0;
			wip_getOpts( ev->channel,
						 WIP_COPT_HTTP_STATUS_CODE, &ret,
						 WIP_COPT_END);
			usr_printf( 1, "status-code : %d\r\n", ret);
			wip_close( ev->channel);
			(( tHttpClientCtx *)ctx)->dataLength = 0;
			(( tHttpClientCtx *)ctx)->DataChannel = NULL;
		}
		break;
		case WIP_CEV_ERROR:
		{
			usr_printf( 1, "WIP_CEV_ERROR\r\n");
			usr_printf( 1, "Socket error : %d (%s). Closing.\r\n",
							ev->content.error.errnum,
							httpclientErrorToMessName( ev->content.error.errnum));
			wip_close( ev->channel);
			(( tHttpClientCtx *)ctx)->dataLength = 0;
			(( tHttpClientCtx *)ctx)->DataChannel = NULL;
		}
		break;
		default:
		break;
	}
}

// =========================================================================
//	CLASSE	:
//	METHODE	: sendHttpGetRequest
// =========================================================================
bool sendHttpGetRequest( LPCTSTR url, LPCTSTR user, LPCTSTR password)
{
	TRACE(( 1, "sendHttpGetRequest"));

	_ASSERT( !g_tHttpClientCtx.DataChannel);
	g_tHttpClientCtx.DataChannel = wip_getFileOpts( g_tHttpClientCtx.CnxChannel,
													( LPSTR)url,
													httpDataHandler,
													&g_tHttpClientCtx,
													WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_GET,
													WIP_COPT_HTTP_HEADER, "Accept", "text/html",
													WIP_COPT_USER, user,
													WIP_COPT_PASSWORD, password,
													WIP_COPT_END);

	return OPE_BIN( g_tHttpClientCtx.DataChannel);
}

// =========================================================================
//	CLASSE	:
//	METHODE	: sendHttpPostRequest
// =========================================================================
bool sendHttpPostRequest( LPCTSTR url, LPCSTR user, LPCTSTR password)
{
	TRACE(( 1, "sendHttpPostRequest"));

	char tmpbuff[256] = {0};

	_ASSERT( !g_tHttpClientCtx.DataChannel);
	g_tHttpClientCtx.DataChannel = wip_getFileOpts( g_tHttpClientCtx.CnxChannel,
													( LPSTR)url,
													httpDataHandler,
													&g_tHttpClientCtx,
													WIP_COPT_HTTP_METHOD, WIP_HTTP_METHOD_POST,
													WIP_COPT_HTTP_HEADER, "Accept", "text/html",
													WIP_COPT_HTTP_HEADER, "Content-Type", "image/jpeg",
													WIP_COPT_HTTP_HEADER, "Content-Length", wm_itoa( g_tHttpClientCtx.dataLength, tmpbuff),
													WIP_COPT_USER, user,
													WIP_COPT_PASSWORD, password,
													WIP_COPT_END);

	return OPE_BIN( g_tHttpClientCtx.DataChannel);
}

thank you.


#2

I think this is a known bug: forum.sierrawireless.com/viewtop … 109&t=4567 :question:


#3

So if i understand, the only way to solve this problem is to close the connexion channel. thank you awneil for the quick response. But i have also observed that the problem does not appear with the POST method. I am going to see it deeply.


#4

Or just re-try the failed request immediately! 8)

That’s interesting! :open_mouth:

I submitted some fairly detailed traces & analysis to Wavecom (only the GET case, IIRC) - if you could also badger them, that might increase the chances of it getting fixed…