Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
inet
active_desktop
active_scrptng
asp.components
asp.db
asp.general
comctl32
comp.packaging
components.dev
dbweb
dhtml_editing
docobjects
html_authoring
html_objmodel
iis
iis.ftp
iis.security
iis.smtp_nntp
indexserver
misc
mshtml_hosting
scripting.jscript
scripting.vbscript
sdk_setup
shell_objmodel
urlmonikers
webbrowser_ctl
wininet
  
 
date: Tue, 1 Jul 2008 06:52:01 -0700,    group: microsoft.public.inetsdk.programming.urlmonikers        back       


text/html MIME filter with separate thread   
I am trying to implement text/html MIME filter. The problem is what filtering 
algorithm is complex and I don't want to do filtering directly in ReportData 
function. So I implemented the algorithm described below(using C++):

func  IInternetProtocolSink::report_data  {     
    if must_be_filtered {
         create_thread(filter_thread);         
         return s_ok;
    } else return sink->report_data();
}

func filter_thread {

     CoInitializeEx(0, COINIT_MULTITHREADED);

     do prot->read() until all is read;
     filter_read_data();
     sink->report_data();
     sink->report_result();      

}

When reportData return S_OK, IE remains active, displaying "loading" 
progress in status string. But "report_data" being called from filter thread 
results in only one "read" call. IE does not wake up, freezing in "loading 
forever" state.

I tried another scheme:

func filter_thread {

    CoInitializeEx(0, COINIT_MULTITHREADED);     

     do prot->read() until all is read;
     filter_read_data();
     
     PROTOCOLDATA pd;
     pd.grfFlags = PD_FORCE_SWITCH;
     pd.dwState = 1234;
     pd.pData = 0;
     pd.cbData = 0;
     HRESULT hr;

     hr = sink->Switch(&pd);

}

func  IInternetProtocol::continue  {     

     if from filter thread {
         sink->report_data();
         sink->report_result();      
     }

}

But IInternetProtocolSink::Switch returns E_FAIL!

Where is my fault? What I am doing wrong? Direct solution without a thread 
works fine, but IE UI freezes(don't respond to mouse events)  until 
ReportData returns and it is unacceptable for me.

thanks.
date: Tue, 1 Jul 2008 06:52:01 -0700   author:   Alexander

Re: text/html MIME filter with separate thread   
Alexander  wrote:
> When reportData return S_OK, IE remains active, displaying "loading"
> progress in status string. But "report_data" being called from filter
> thread results in only one "read" call.

What parameters are you passing when calling ReportData?

What are you returning from your implementation of 
IInternetProtocol::Read? Make sure to fill the buffer with no more data 
than the specified buffer size, and return S_OK if you have more data to 
report, and S_FALSE otherwise.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Tue, 1 Jul 2008 10:47:57 -0400   author:   Igor Tandetnik

Re: text/html MIME filter with separate thread   
"Igor Tandetnik" wrote:

> Alexander  wrote:
> What parameters are you passing when calling ReportData?

Here is the code being executed after filter thread having its job done:
(code is executed from filter thread!)

	data.object->outgoing_prot_sink->ReportData
		(BSCF_FIRSTDATANOTIFICATION | 
		 BSCF_LASTDATANOTIFICATION | 
		 BSCF_DATAFULLYAVAILABLE,
		 data.object->buffer.size(), data.object->buffer.size());
	
	data.object->outgoing_prot_sink->ReportResult(S_OK, S_OK, NULL);


data.object->buffer is buffer with filtered data. 

This results in one Read call, with 8196 bytes of data requested(total 
amount is ~30000 bytes in my test case). 

As far as I understand there must be the serie if reads, until my Read 
handler return S_FALSE.

> What are you returning from your implementation of 
> IInternetProtocol::Read? Make sure to fill the buffer with no more data 
> than the specified buffer size, and return S_OK if you have more data to 
> report, and S_FALSE otherwise.

here is my Read implementation:

		if(buffer_p < buffer.size()){
			int to_read = (buffer.size() - buffer_p) <= cb ? (buffer.size() - 
buffer_p) : cb;
			copy(buffer.begin() + buffer_p , buffer.begin() +  buffer_p + to_read, 
(char*)pv);
			buffer_p += to_read;
			*pcbRead = to_read;
			return buffer_p >= buffer.size() ? S_FALSE : S_OK;
		} else {
			return S_FALSE;
		}
date: Wed, 2 Jul 2008 01:54:03 -0700   author:   Alexander

Re: text/html MIME filter with separate thread   
"Alexander"  wrote in message
news:07E03E72-0EDB-4630-9818-9FC392A7C67B@microsoft.com
> data.object->outgoing_prot_sink->ReportData
> (BSCF_FIRSTDATANOTIFICATION |
> BSCF_LASTDATANOTIFICATION |
> BSCF_DATAFULLYAVAILABLE,
> data.object->buffer.size(), data.object->buffer.size());
>
> data.object->outgoing_prot_sink->ReportResult(S_OK, S_OK, NULL);
>
> here is my Read implementation:
>
> if(buffer_p < buffer.size()){
> int to_read = (buffer.size() - buffer_p) <= cb ? (buffer.size() -
> buffer_p) : cb;
> copy(buffer.begin() + buffer_p , buffer.begin() +  buffer_p + to_read,
> (char*)pv);
> buffer_p += to_read;
> *pcbRead = to_read;
> return buffer_p >= buffer.size() ? S_FALSE : S_OK;
> } else {
> return S_FALSE;
> }

I don't see anything obviously wrong in your code (assuming buffer_p is 
initialized to 0 at some point). If you have a small sample that 
reproduces the problem, you can email it to me at itandetnik@mvps.org, 
I'll look at it.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Wed, 2 Jul 2008 08:07:38 -0400   author:   Igor Tandetnik

Re: text/html MIME filter with separate thread   
Igor, I have emailed you a simple project that illustrates my problem.


"Igor Tandetnik" wrote:

> I don't see anything obviously wrong in your code (assuming buffer_p is 
> initialized to 0 at some point). If you have a small sample that 
> reproduces the problem, you can email it to me at itandetnik@mvps.org, 
> I'll look at it.
> -- 
> With best wishes,
>     Igor Tandetnik
> 
> With sufficient thrust, pigs fly just fine. However, this is not 
> necessarily a good idea. It is hard to be sure where they are going to 
> land, and it could be dangerous sitting under them as they fly 
> overhead. -- RFC 1925 
> 
> 
>
date: Fri, 4 Jul 2008 09:51:00 -0700   author:   Alexander

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us