Nick Aschberger | 1 Jun 03:05
Favicon

Re: Boost ASIO - SO_LINGER Socket option is not working

Igor R wrote:
I have a situation where at termination of my program, I am closing my socket, and then deleting the socket object. Note, we are using non-asynchronous (blocking) accesses at this point, boost is version 1.36. In some cases, the socket has had some data written to it, but that data is never received by the connected client - because I destroy the socket before the data is sent. So, SO_LINGER is the socket option that is supposed to solve all my worries (it should wait on close for any unsent data to be sent), however I am using it and there is no effect. I presume because I'm doing something wrong.
SO_LINGER is just forwarded as-is to the native socket API, so if it doesn't work there's some problem with the socket. What I couldn't understand from your description is whether you used sync. or async. i/o, and from what thread (same as close() or some other). Could you please clarify these points?
Hi Igor,

There is only one thread in this program, and we are using sync (blocking) accesses.
So it is definately the same thread that writes some data on the socket and then deletes the socket.

Am I setting the property correctly on the socket? Does it need to be set on the acceptor or something instead/as well?

cheers

Nick
_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Sohail Somani | 1 Jun 05:24
Gravatar

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

Robert Ramey wrote:
> Sohail Somani wrote:
>> Still interested in forward compatibility, if you are inclined to
>> elaborate a little.
> 
> Here we go.  Basically, backward compatibility is handled by code
> that looks like the following:
> 
> template<class Archive>
> void save(Archive &ar, const unsigned int version){
>     ar << original_stuff
>     ar << stuff_added_version_3;
>     ar << stuff_added_version_4;
> }
> 
> template<class Archive>
> void load(Archive &ar, const unsigned int version){
>     ar >> original_stuff;
>     if(version > 3)
>         ar >> stuff_added_version_3;
>     if(version > 4)
>         ar >> stuff_added_version_4;
>     ...
> }
> 
> So what we need to do is replace the save above with:
> 
> template<class Archive>
> void save(Archive &ar, const unsigned int version) const {
>     ar << original_stuff
>     if(version > 3)
>         ar << stuff_added_version_3;
>     if(version > 4)
>         ar << stuff_added_version_4;
> }

Just typing out loud: Forward compatibility is the ability to load an
archive with a version of 4 into an application with a version of 3.

So if we have std::vector<SomeClass> and in version 4, I add an int to
SomeClass, I'm pretty sure it would cause the whole thing to go boom
when loading an archive from version 4 into version 3.

I'm not sure if the above avoids this problem, does it?

--

-- 
Sohail Somani
http://uint32t.blogspot.com
Robert Ramey | 1 Jun 06:46

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

Sohail Somani wrote:
> Robert Ramey wrote:
>> Sohail Somani wrote:
>>> Still interested in forward compatibility, if you are inclined to
>>> elaborate a little.
>>
>> Here we go.  Basically, backward compatibility is handled by code
>> that looks like the following:
>>
>> template<class Archive>
>> void save(Archive &ar, const unsigned int version){
>>     ar << original_stuff
>>     ar << stuff_added_version_3;
>>     ar << stuff_added_version_4;
>> }
>>
>> template<class Archive>
>> void load(Archive &ar, const unsigned int version){
>>     ar >> original_stuff;
>>     if(version > 3)
>>         ar >> stuff_added_version_3;
>>     if(version > 4)
>>         ar >> stuff_added_version_4;
>>     ...
>> }
>>
>> So what we need to do is replace the save above with:
>>
>> template<class Archive>
>> void save(Archive &ar, const unsigned int version) const {
>>     ar << original_stuff
>>     if(version > 3)
>>         ar << stuff_added_version_3;
>>     if(version > 4)
>>         ar << stuff_added_version_4;
>> }
>
> Just typing out loud: Forward compatibility is the ability to load an
> archive with a version of 4 into an application with a version of 3.

To me forward compatability is he ability to create a version 3 archive
with a version 4 program.  Hmmm - now that I read that, it doesn't
look right. I guess that should be called "complete" backward
compatibility.  I don't see how it is possible while writing version
3 progam to know what version 4 is going to save.

>
> So if we have std::vector<SomeClass> and in version 4, I add an int to
> SomeClass, I'm pretty sure it would cause the whole thing to go boom
> when loading an archive from version 4 into version 3.
>
> I'm not sure if the above avoids this problem, does it? 
Steven Watanabe | 1 Jun 05:54
Picon

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

AMDG

Robert Ramey wrote:
> Sohail Somani wrote:
>   
>> Just typing out loud: Forward compatibility is the ability to load an
>> archive with a version of 4 into an application with a version of 3.
>>     
>
> To me forward compatability is he ability to create a version 3 archive
> with a version 4 program.  Hmmm - now that I read that, it doesn't
> look right. I guess that should be called "complete" backward
> compatibility.  I don't see how it is possible while writing version
> 3 progam to know what version 4 is going to save.
>   

It would be possible in special cases.  For example, the
version 4 archive could add information that the version
3 program knows to skip somehow.

In Christ,
Steven Watanabe
Zachary Turner | 1 Jun 06:12
Picon

Boost.Asio extensible to non network i/o?

I've been reading over the documentation for Boost.Asio and as far as I can tell the documentation makes no mention whatsoever about using Asio for anything other than sockets programming.  Suppose I wanted to implemented a simple file transfer client (I say client because the server will not be in C++) that reads files off of the disk and sends them to the server.  I'd like to do it asynchronously.  What would be the basic steps needed to do this with Boost.Asio, if it is indeed even possible?  I'd specifically like it to use I/O Completion Ports on Windows if possible, and whatever on Linux.  I'd like to be able to configure the number of worker threads on the backend, so that for example I can read from N files at once, or from N different locations in the same file.  I'd also like to have a single "controller" thread that receives all the events regarding when reads or writes complete, so that I don't have to use any kind of locking to synchronize things.

As a final "nice-to-have", I'd like to be able to plug my own types of "actions" into the model, things that aren't really I/O but that I still want to execute asynchronously that would sit in between a completed disk read and the initiation of writing that same data to the socket.  Think, for example, of encrypting the file before sending.  I don't want to block on the encryption, so it would be nice if I could do that asynchronously and still be notified of its completion through the same interface.  I know I can do all this directly in windows (which is the only system api i'm intimately familiar with) via IOCP, so I'm hoping something similar can be achieved with Boost.Asio.

Thanks

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Sohail Somani | 1 Jun 06:25
Gravatar

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

Steven Watanabe wrote:
> AMDG
> 
> Robert Ramey wrote:
>> Sohail Somani wrote:
>>  
>>> Just typing out loud: Forward compatibility is the ability to load an
>>> archive with a version of 4 into an application with a version of 3.
>>>     
>>
>> To me forward compatability is he ability to create a version 3 archive
>> with a version 4 program.  Hmmm - now that I read that, it doesn't
>> look right. I guess that should be called "complete" backward
>> compatibility.  I don't see how it is possible while writing version
>> 3 progam to know what version 4 is going to save.
>>   
> 
> It would be possible in special cases.  For example, the
> version 4 archive could add information that the version
> 3 program knows to skip somehow.

Right, so one totally naive way the library could do it would be to
inject a marker after every serialization call. This way, the version 3
application could simply search for the marker after every serialization
call in order to set up the next serialization call.

Basically, I am saying that version 4 of the app writes out:

foo 1 2 3 |END_MARKER| foo 4 5 6 |END_MARKER|

And version 3, which can only read the first two ints, reads foo 1 2 and
then resets the stream pointer (or whatever) to right after |END_MARKER|.

If that makes ANY sense, I will be happy.

--

-- 
Sohail Somani
http://uint32t.blogspot.com
Sohail Somani | 1 Jun 06:26
Gravatar

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

Robert Ramey wrote:
> Sohail Somani wrote:
>> Just typing out loud: Forward compatibility is the ability to load an
>> archive with a version of 4 into an application with a version of 3.
> 
> To me forward compatability is he ability to create a version 3 archive
> with a version 4 program.  Hmmm - now that I read that, it doesn't
> look right. I guess that should be called "complete" backward
> compatibility.  I don't see how it is possible while writing version
> 3 progam to know what version 4 is going to save.

See my reply to Steven W.

--

-- 
Sohail Somani
http://uint32t.blogspot.com
Robert Ramey | 1 Jun 07:58

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

Sohail Somani wrote:
> Steven Watanabe wrote:
>> AMDG
>>
>> Robert Ramey wrote:
>>> Sohail Somani wrote:
>>>
>>>> Just typing out loud: Forward compatibility is the ability to load
>>>> an archive with a version of 4 into an application with a version
>>>> of 3.
>>>>
>>>
>>> To me forward compatability is he ability to create a version 3
>>> archive with a version 4 program.  Hmmm - now that I read that, it
>>> doesn't look right. I guess that should be called "complete"
>>> backward compatibility.  I don't see how it is possible while
>>> writing version 3 progam to know what version 4 is going to save.
>>>
>>
>> It would be possible in special cases.  For example, the
>> version 4 archive could add information that the version
>> 3 program knows to skip somehow.
>
> Right, so one totally naive way the library could do it would be to
> inject a marker after every serialization call. This way, the version
> 3 application could simply search for the marker after every
> serialization call in order to set up the next serialization call.
>
> Basically, I am saying that version 4 of the app writes out:
>
> foo 1 2 3 |END_MARKER| foo 4 5 6 |END_MARKER|
>
> And version 3, which can only read the first two ints, reads foo 1 2
> and then resets the stream pointer (or whatever) to right after
> |END_MARKER|.
>
> If that makes ANY sense, I will be happy.

You might be able to implement that for xml archives by
deriving from xml_iarchive.

Robert Ramey
Sohail Somani | 1 Jun 07:28
Gravatar

Re: Boost Serialization + Forward compatibility [was Re: boost::serialization and PHP websites]

Robert Ramey wrote:
> Sohail Somani wrote:
>> Basically, I am saying that version 4 of the app writes out:
>>
>> foo 1 2 3 |END_MARKER| foo 4 5 6 |END_MARKER|
>>
>> And version 3, which can only read the first two ints, reads foo 1 2
>> and then resets the stream pointer (or whatever) to right after
>> |END_MARKER|.
>>
>> If that makes ANY sense, I will be happy.
> 
> You might be able to implement that for xml archives by
> deriving from xml_iarchive.

I never use xml archives but xml in general does have this property. I'd
like the solution to apply to all archives though.

--

-- 
Sohail Somani
http://uint32t.blogspot.com
Roman Shmelev | 1 Jun 08:33
Picon

Re: Boost.Asio extensible to non network i/o?

Async file reading could be done in Windows. What I can give is the
link to Russian blog:
http://evgeny-lazin.blogspot.com/2008/12/boostasio.html

Everything that you described - could be achieved by asio.
You can configure number of working threads by running
io_service.run() from each of them.
I guess, at this point you _will_ need to syncronize access to
"controller" through some mutex or asio::strands
and it will not significantly lower performance.

Gmane