Thanks for your time.
I sent you whole source code (to mail [EMAIL PROTECTED]). It is MSVS.2003
solution with one project. Application's puropse is to discover necko
architecture for our company. It implements a simple protocol for
transfering files from one computer to another. It is also used to
discover possibilities of using javascipt and xpcom.
Base part is an instance of service (SPO_TransferService) what is able
to send files in the background from prepaired stream and also has
callback to receive file from some other client running the same
service. It works in p2p manor.
To send and to receive data I use separate instance of
SPO_SampleDataReceive and SPO_SampleDataSend objects on each side of
the transfer connection (On one computer is instance of sending object
and on the second is related instance of receiving object, each pair to
one file transfer and one tcp connection - may work in parallel). It is
instantiated internaly by the SPO_TransferService. These objects are
automaticly released after its work is finished or connection is
broken.
Send object is using async stream copier to push data to pipe where
from it is pushed to the socket's output stream.
Receive object is only giving notification about incoming data and
gives reference to the pipe (to this pipe are pushed data from the
socket's input stream) to read the file from. In the main.cpp file is
implementation of the listener to incoming file. In the listener's
OnIncomingData method is also used async stream copier to load data
from the accepted transfer to the file.
Approach with pipe joined to input stream of the socket was choiced
because there was a collision between the input stream pump and the
async stream copier. Input stream pump is using stream's AsyncWait()
method and stream copier is using it too - collision occurs.
Main parts of application (better to call it test) are:
Main.cpp - the main thread loop and instantiating the service.
Implmenetation of the service callback storing the received file
SPO_DirectConnectionMechanism.cpp - generic connectino establishment
mechanism implmenentation. OnEstablish is the callback.
SPO_SampleDataReceive.cpp - mentioned above
SPO_SampleDataSend.cpp - dtto
SPO_SampleDataTransfer.cpp - the base class for two previews files. It
encapsulates mechanism for using the socket connection - assigns pipe
to the output stream to write data asynchronously or assigns stream
pump to watch events on the input stream.
SPO_TransferService.cpp - the service implementation
SPO_TransportServerTcp.cpp - generic server implememtation, an
extension to existing necko's nsIServerSocket. It simply propagate the
OnSocketAccepted event of the server socket. This event may be
propagated to other then the main thread (where and only where the
nsServerSocket works) using simply PostEvent. See lines 132 and 145 to
change target thread of incoming transport accepting.
See line 90 and following in SPO_SampleDataTransfer.cpp. Here I tried
to solve my problem with event queue.
If OnTrasnportAccept is called in other then the main thread the pump
is not working. Connection is established succesfully and async obejcts
(Send and Received) are not released. Only the sending object is
released after READWRITE timeout - set to 10 seconds.
Thanks for your time spent on this piece of code. I would be very
gratefull to you for any suggestions.
-hb-
_______________________________________________
Mozilla-netlib mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-netlib