|
From: CVS C. to T. <the...@li...> - 2011-08-15 23:48:11
|
Revision: 664
http://themis.svn.sourceforge.net/themis/?rev=664&view=rev
Author: z3r0_one
Date: 2011-08-15 23:48:04 +0000 (Mon, 15 Aug 2011)
Log Message:
-----------
A start on removing some deadlocks in TCP/HTTP layers.
Modified Paths:
--------------
trunk/themis/framework/connection.cpp
trunk/themis/framework/tcpmanager.cpp
trunk/themis/modules/CSSRenderer/CSSRendererView.cpp
trunk/themis/modules/http/httpv4.cpp
Modified: trunk/themis/framework/connection.cpp
===================================================================
--- trunk/themis/framework/connection.cpp 2011-07-30 18:48:36 UTC (rev 663)
+++ trunk/themis/framework/connection.cpp 2011-08-15 23:48:04 UTC (rev 664)
@@ -89,8 +89,8 @@
}
int32 Connection::CountConnections() {
int32 count=0;
- BAutolock alock(ListLock);
- if (alock.IsLocked())
+ //BAutolock alock(ListLock);
+ //if (alock.IsLocked())
if (ConnectionList!=NULL)
count=ConnectionList->CountItems();
return count;
@@ -452,17 +452,19 @@
if (lock.LockWithTimeout(10000)==B_OK) {
if (socket_id>=0) {
struct timeval tv;
- tv.tv_sec=2;
- tv.tv_usec=0;
+ tv.tv_sec=0;//2;
+ tv.tv_usec=50000;
struct fd_set fds;
FD_ZERO(&fds);
FD_SET(socket_id,&fds);
int32 err=select(socket_id+1,&fds,NULL,NULL,&tv);
- if (err<=0) {
+ if (err<0) {
+ //printf("IsDataWaiting socket error\n");
lock.Unlock();
return false;
}
waiting_data=FD_ISSET(socket_id,&fds);
+ printf("IsDataWaiting: %s\n",(waiting_data ? "yes":"no"));
}
lock.Unlock();
}
@@ -744,8 +746,8 @@
}
int32 Connection::IsInUse() {
int32 isinuse=0;
- BAutolock alock(lock);
- if (alock.IsLocked())
+ //BAutolock alock(lock);
+ //if (alock.IsLocked())
isinuse=in_use;
return isinuse;
}
@@ -788,8 +790,8 @@
// fflush(stdout);
// BAutolock alock(lock);
if (lock.LockWithTimeout(15000)==B_OK) {
- int16 size=10240;
- int16 bytes=0;
+ int32 size=1048576;
+ int32 bytes=0;
unsigned char *data=new unsigned char[size];
if (!IsInUse())
{
@@ -898,7 +900,7 @@
data=NULL;
lock.Unlock();
}
-// printf("Connection::Retrieve() is done.\n");
+ printf("Connection::Retrieve() is done.\n");
}
int32 Connection::LastUsed(){
return lastusedtime;
Modified: trunk/themis/framework/tcpmanager.cpp
===================================================================
--- trunk/themis/framework/tcpmanager.cpp 2011-07-30 18:48:36 UTC (rev 663)
+++ trunk/themis/framework/tcpmanager.cpp 2011-08-15 23:48:04 UTC (rev 664)
@@ -144,7 +144,7 @@
if (connection == NULL || !Connection::HasConnection(connection))
{
lock.Unlock();
- snooze(10000);
+ //snooze(10000);
continue;
}
if (connection->IsConnected())
@@ -162,7 +162,9 @@
{
connection->RetrieveData();
if (connection->owner!=NULL)
+ {
connection->owner->DataIsWaiting(connection);
+ }
}
}
} else
@@ -202,11 +204,11 @@
}
lock.Unlock();
}
- snooze(10000);
+ // snooze(10000);
}
}
- snooze(25000);
+ //snooze(25000);
// release_sem(process_sem_2);
// }
@@ -220,8 +222,8 @@
Connection *TCPManager::CreateConnection(NetworkableObject *net_obj,const char *host,uint16 port,bool secure,bool asynch) {
//printf("CreateConnection begun\n");
Connection *connection=NULL;
- BAutolock alock(lock);
- if (alock.IsLocked()) {
+// BAutolock alock(lock);
+// if (alock.IsLocked()) {
int32 connections=0;
Connection *target_connection=NULL;
connections=Connection::CountConnections();
@@ -251,7 +253,7 @@
sessions_created++;
}
- }
+// }
//printf("CreateConnection is done: %p\n",connection);
return connection;
}
Modified: trunk/themis/modules/CSSRenderer/CSSRendererView.cpp
===================================================================
--- trunk/themis/modules/CSSRenderer/CSSRendererView.cpp 2011-07-30 18:48:36 UTC (rev 663)
+++ trunk/themis/modules/CSSRenderer/CSSRendererView.cpp 2011-08-15 23:48:04 UTC (rev 664)
@@ -129,7 +129,7 @@
}
Window()->SetTitle(title.c_str());
SetViewColor(B_TRANSPARENT_COLOR);
-// mView->RetrieveResources();
+ mView->RetrieveResources();
}
Modified: trunk/themis/modules/http/httpv4.cpp
===================================================================
--- trunk/themis/modules/http/httpv4.cpp 2011-07-30 18:48:36 UTC (rev 663)
+++ trunk/themis/modules/http/httpv4.cpp 2011-08-15 23:48:04 UTC (rev 664)
@@ -35,6 +35,7 @@
#include <ctype.h>
#include <Autolock.h>
#include <String.h>
+#include <string.h>
#define PlugIDdef 'http'
#define PlugNamedef "Network (http)"
@@ -322,7 +323,7 @@
if (build_request_thid!=0)
wait_for_thread(build_request_thid,&status);
build_request_thid=spawn_thread(BuildRequest_th,"http - build request", B_LOW_PRIORITY,bri);
-// printf("HTTPv4 (Heartbeat):\tbuild request thread id %ld\n",build_request_thid);
+ printf("HTTPv4 (Heartbeat):\tbuild request thread id %ld\n",build_request_thid);
resume_thread(build_request_thid);
wait_for_thread(build_request_thid,&status);
@@ -480,7 +481,8 @@
return STATUS_NOTIFICATION_FAILED;
if (connection->NotifiedConnect())
return STATUS_NOTIFICATION_SUCCESSFUL;
- request_lock.Lock();
+ BAutolock alock(&request_lock);
+// request_lock.Lock();
// printf("HTTPv4 Connection established! %p\n",connection);
http_request_info_st *current=http_request_list;
while(current!=NULL)
@@ -503,7 +505,7 @@
}
current=current->next;
}
- request_lock.Unlock();
+// request_lock.Unlock();
return STATUS_NOTIFICATION_SUCCESSFUL;
}
@@ -631,8 +633,14 @@
{
if (_terminate_)
return STATUS_NOTIFICATION_FAILED;
+ printf("\n\tHTTPv4::DataIsWaiting\n");
if (request_lock.LockWithTimeout(10000)==B_OK)
{
+ unsigned char *buffer=(unsigned char*)malloc(BUFFER_SIZE);
+ off_t bytes_received=0L,data_size=0L;
+ off_t buffer_size=BUFFER_SIZE;
+ memset(buffer,0,BUFFER_SIZE);//we do an initial wipe of memory just to start things off fresh
+ printf("\nrequest lock achieved\n");
if (connection->DataSize()>0)
{
http_request_info_st *current=http_request_list;
@@ -640,17 +648,44 @@
{
if (current->connection==connection)
{
-// printf("Data is waiting for %s (s: %ld u: %ld ; %Ld bytes)\n",current->url,current->site_id,current->url_id,current->connection->DataSize());
+ printf("Data is waiting for %s (s: %ld u: %ld ; %Ld bytes)\n",current->url,current->site_id,current->url_id,current->connection->DataSize());
if ((current->internal_status&STATUS_RESPONSE_RECEIVED_FROM_SERVER)==0)
current->internal_status|=STATUS_RESPONSE_RECEIVED_FROM_SERVER;
if ((current->internal_status&STATUS_RECEIVING_DATA)==0)
current->internal_status|=STATUS_RECEIVING_DATA;
+ int32 data_size = current->connection->DataSize();
+ if( data_size > 0)
+ {
+ if(data_size > buffer_size)
+ {
+ buffer = (unsigned char*) realloc(buffer,data_size);
+ memset(buffer,0,data_size);
+ buffer_size = data_size;
+ }
+ else
+ {
+ if((data_size < BUFFER_SIZE) && (buffer_size > BUFFER_SIZE))
+ {
+ buffer = (unsigned char*) realloc(buffer, BUFFER_SIZE);
+ memset(buffer,0,BUFFER_SIZE);
+ buffer_size = BUFFER_SIZE;
+ }
+ else
+ memset(buffer,0,buffer_size);
+ }
+ bytes_received = current->connection->Receive(buffer,buffer_size);
+ ProcessData(current,buffer,bytes_received);
+ current->internal_status ^= STATUS_RECEIVING_DATA;
+ }
break;
}
current=current->next;
}
}
+ memset(buffer,0,BUFFER_SIZE);
+ free(buffer);
request_lock.Unlock();
+ printf("\nrequest_lock released\n");
return STATUS_NOTIFICATION_SUCCESSFUL;
}
return STATUS_NOTIFICATION_FAILED;
@@ -805,15 +840,18 @@
bri->url=new char[strlen(url)+1];
memset((char*)bri->url,0,strlen(url)+1);
strcpy((char*)bri->url,url);
- if (build_request_thid==0)
+ build_request_thid = find_thread("http - build request");
+ printf("build_request_thid: %d\n",build_request_thid);
+ if (build_request_thid==B_NAME_NOT_FOUND && request_build_lock.IsLocked() == false )
{
build_request_thid=spawn_thread(BuildRequest_th,"http - build request", B_LOW_PRIORITY,bri);
-// printf("HTTPv4:\tbuild request thread id %ld\n",build_request_thid);
+ printf("HTTPv4:\tbuild request thread id %ld\n",build_request_thid);
resume_thread(build_request_thid);
wait_for_thread(build_request_thid,&status);
build_request_thid=0;
-// printf("HTTPv4 (RB): build request thread completed\n");
+ printf("HTTPv4 (RB): build request thread completed\n");
} else {
+
//add it to a queue, and check that periodically in the heartbeat to see if we have anything we need to process.
request_queue->AddItem(bri);
}
@@ -1011,10 +1049,10 @@
//bri = build request info
HTTPv4 *http=bri->http;
// status_t status=B_ERROR;
-// printf("HTTPv4:\tBuild request for url: %s\n",bri->url);
- http->request_lock.Lock();
+ printf("HTTPv4:\tBuild request for url: %s\n",bri->url);
+// http->request_lock.Lock();
http_request_info_st *current_item=NULL,*new_item=new http_request_info_st;
- http->request_lock.Unlock();
+// http->request_lock.Unlock();
new_item->url=bri->url;
new_item->site_id=bri->site_id;
new_item->url_id=bri->url_id;
@@ -1511,6 +1549,7 @@
}//Request has been built but server connection hasn't been established begin
if ((current->internal_status&STATUS_CONNECTED_TO_SERVER)!=0)
{//we are connected to the server, so process here begin
+ /*TEST Ray 8/15/2011
if ((current->internal_status&STATUS_RECEIVING_DATA)!=0)
{//we have received data that needs to be processed begin
//we don't have to make sure the memory is clear here
@@ -1548,11 +1587,11 @@
current->internal_status^=STATUS_RECEIVING_DATA;
/*
special case; we want to receive data as quickly as possible.
- */
+ * /
previous=current;
current=current->next;
http->request_lock.Unlock();
- snooze(10000);
+ //snooze(10000);
continue;
} else
{
@@ -1566,6 +1605,7 @@
// printf("DataSize() returned size %Ld\n",data_size);
}
+
}
}//we have received data that needs to be processed end
else
@@ -1573,6 +1613,7 @@
if ((current->internal_status&STATUS_PROCESSING_TIMED_OUT)!=0)
ProcessChunkedData(current);
}
+ TEST Ray 8/15/2011*/
}//we are connected to the server, so process here end
//process current http request end
current=current->next;
@@ -1671,7 +1712,9 @@
printf("HTTPv4: Unknown HTTP response code: %d - %s\n",request->http_status_code,request->http_status_message);
}
+ printf("\nDone processing headers; moving on to ProcessData2\n");
ProcessData2(request,(unsigned char*)(end_of_header+4),length-((end_of_header+4)-(char*)buffer));
+ printf("\nDone with ProcessData2 (post header)\n");
} else
{
request->internal_status|=STATUS_HEADERS_STARTED;//we have more headers to receive and process
@@ -1766,7 +1809,9 @@
// printf("header length: %ld\n" ,((end_of_header+4)-(char*)data)+orig_head_len);
// printf("length received: %ld\n",length);
// printf("difference: %ld\n",length-((end_of_header+4)-(char*)data)+orig_head_len);
+ printf("\nDone processing headers (2), moving on to ProcessData2\n");
ProcessData2(request,(unsigned char*)(end_of_header+4),length-((end_of_header+4)-(char*)data)+orig_head_len);
+ printf("\nDone with ProcessData2 (2)\n");
}
} else
@@ -1774,7 +1819,9 @@
//if headers have been completed, process data
if (((request->internal_status&STATUS_HEADERS_STARTED)!=0) && ((request->internal_status&STATUS_HEADERS_COMPLETED)!=0))
{
+ printf("\nAbout to ProcessData2\n");
ProcessData2(request,buffer,length);
+ printf("\nDone with ProcessData2\n");
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|