
Hi guys...I would to make a simple multi process (not thread) server. I've seen the iterative example in which it handles one request at a time. Instead I need to handle more requests(more on less 10) at the same time. In the classic c and c++ examples, I've seen that the server is designed like the following: int listensd, connsd; // listening socket and conection socket pid_t pid; //process id listensd=socket(....); bind(listensd,...); listen(listensd,...); for(;;) { connsd=accept(listensd,...); if((pid=fork())==0) //child process { close(listensd); //close the listen socket do_it(connsd); //serve the request close(connsd); //close the connection socket exit(0); } close(connsd); //the parent closes the connection socket } Is it possible to do something like that with boost? I really don't know how obtain the two different socket, because in boost all the function (listen, bind, accept, etc.) return void. Thank you...

Hi guys...I would to make a simple multi process (not thread) server. I've seen the iterative example in which it handles one request at a time. Instead I need to handle more requests(more on less 10) at the same time. In the classic c and c++ examples, I've seen that the server is designed like the following:
int listensd, connsd; // listening socket and conection socket pid_t pid; //process id listensd=socket(....); bind(listensd,...); listen(listensd,...); for(;;) {
connsd=accept(listensd,...); if((pid=fork())==0) //child process { close(listensd); //close the listen socket do_it(connsd); //serve the request close(connsd); //close the connection socket exit(0); } close(connsd); //the parent closes the connection socket }
Is it possible to do something like that with boost? I really don't know how obtain the two different socket, because in boost all the function (listen, bind, accept, etc.) return void.
ASIO objects wrap native handles, and you can access them using native_type() member function. But if all you need is to process simultanious requests efficiently, you don't need to launch neither threads nor processes. All you need is to stick with ASIO asynchronous model - just like explained in the tutorial/examples.

Thank you for your reply,what do you mean with native_type ? is a boost
function?
I need to make a multi process TCP Server..so I think it is mandatory to me to
"parallelize" the server with process...are you sure that is enough to use the
asynchronous model?
________________________________
Da: Igor R
Hi guys...I would to make a simple multi process (not thread) server. I've seen the iterative example in which it handles one request at a time. Instead I need to handle more requests(more on less 10) at the same time. In the classic c and c++ examples, I've seen that the server is designed like the following:
int listensd, connsd; // listening socket and conection socket pid_t pid; //process id listensd=socket(....); bind(listensd,...); listen(listensd,...); for(;;) {
connsd=accept(listensd,...); if((pid=fork())==0) //child process { close(listensd); //close the listen socket do_it(connsd); //serve the request close(connsd); //close the connection socket exit(0); } close(connsd); //the parent closes the connection socket }
Is it possible to do something like that with boost? I really don't know how obtain the two different socket, because in boost all the function (listen, bind, accept, etc.) return void.
ASIO objects wrap native handles, and you can access them using native_type() member function. But if all you need is to process simultanious requests efficiently, you don't need to launch neither threads nor processes. All you need is to stick with ASIO asynchronous model - just like explained in the tutorial/examples. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Thank you for your reply,what do you mean with native_type ? is a boost function?
It's a member function of asio objects. Eg., calling yourSocket.native_type() gives you a native socket handle. In versions prior ro 1.46 it's called native_handle(), IIRC.
I need to make a multi process TCP Server..so I think it is mandatory to me to "parallelize" the server with process...are you sure that is enough to use the asynchronous model?
Well, I don't know where your requirements come from and what you do in your "process_it()" function. If it's an excercise in making multiple processes with fork(), or if you have heavy processing task and cannot enqueue it to a dedicated thread for some reason -- then you probably don't have a choice. But note that your solution is non-portable and not scalable. Think what happens with your server under high load - say, 10000 incoming requests. Are you sure launching 10000 processes would be a good idea?

Yes yes I know that this choice is not scalable and portable...but I only have
10 or at most 15 request...so I think that a process could be a
solution..besides I need that each connection are separated from the other..
However, excuse but I'm a noob...for example..to obtain the listen socket:
int listensd=socket(....);
I have to do something like this?:
boost::asio::ip::tcp::socket s;
int listen sd=s.native_type();
________________________________
Da: Igor R
Thank you for your reply,what do you mean with native_type ? is a boost function?
It's a member function of asio objects. Eg., calling yourSocket.native_type() gives you a native socket handle. In versions prior ro 1.46 it's called native_handle(), IIRC.
I need to make a multi process TCP Server..so I think it is mandatory to me to "parallelize" the server with process...are you sure that is enough to use the asynchronous model?
Well, I don't know where your requirements come from and what you do in your "process_it()" function. If it's an excercise in making multiple processes with fork(), or if you have heavy processing task and cannot enqueue it to a dedicated thread for some reason -- then you probably don't have a choice. But note that your solution is non-portable and not scalable. Think what happens with your server under high load - say, 10000 incoming requests. Are you sure launching 10000 processes would be a good idea? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

thank you, it works...my problem now is how to get the connection socket used by
acceptor...
________________________________
Da: Igor R
int listensd=socket(....);
I have to do something like this?: boost::asio::ip::tcp::socket s; int listen sd=s.native_type();
Sorry, I was mistaken, it's called native(). tpc::socket::native_type sd = s.native(); Certainly, native_type here is a typedef of some integral type. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

1)Hi guys...I've seen the tutorial and the example, but I don't understand why
the function listen() of the acceptor is never called...despite that new
connections arrived...how is it possible?
2)By the following instructions, I create a socket(a connection socket?????or a
listening socket???) and then pass it at the acceptor
tcp::socket sock (ioserv);
acceptor.accept(sock);
3)Now, how can I obtain the other socket(connection or listening dependind on
the previous question)?
In C, I simply use the socket descriptors which are passed as arguments to the
various functions (listen, bind, accept) and these functions return in some
cases another socket descriptor.
Then these descriptors are used to closed the different sockets.
Here, with boost, I don't know how make that.
Please help me.
Thanks..
________________________________
Da: Igor R
thank you, it works...my problem now is how to get the connection socket used by acceptor...
acceptor.native()? _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On Fri, 04 Mar 2011 08:26:15 +0100, Marco Piacentini
1)Hi guys...I've seen the tutorial and the example, but I don't understand why the function listen() of the acceptor is never called...despite that new connections arrived...how is it possible?
The examples from boost page don't work for you? If they do, there is obviously something there that you forgotten in your code.
2)By the following instructions, I create a socket(a connection socket?????or a listening socket???) and then pass it at the acceptor
tcp::socket sock (ioserv); acceptor.accept(sock);
3)Now, how can I obtain the other socket(connection or listening dependind on the previous question)? In C, I simply use the socket descriptors which are passed as arguments to the various functions (listen, bind, accept) and these functions return in some cases another socket descriptor. Then these descriptors are used to closed the different sockets. Here, with boost, I don't know how make that. Please help me. Thanks..
You are having problems with *basic things*, do ***RTFM*** end experiment. Nobody should do your job for you. --Slava

I've read all the manual, all the tutorials, all the example and I don't want
that someone make the job for me.
I came from java world, where all is documented, all is explained in detail...
I thought that a mailing list was a place where obtain help, especially if the
question are detailed (I don't ask "make something for me. stop.").
I think your answer is rude, so reserve the expression RTFM for other people.
________________________________
Da: "Viatcheslav.Sysoltsev@h-d-gmbh.de"
1)Hi guys...I've seen the tutorial and the example, but I don't understand why the function listen() of the acceptor is never called...despite that new connections arrived...how is it possible?
The examples from boost page don't work for you? If they do, there is obviously something there that you forgotten in your code.
2)By the following instructions, I create a socket(a connection socket?????or a listening socket???) and then pass it at the acceptor
tcp::socket sock (ioserv); acceptor.accept(sock);
3)Now, how can I obtain the other socket(connection or listening dependind on the previous question)? In C, I simply use the socket descriptors which are passed as arguments to the various functions (listen, bind, accept) and these functions return in some cases another socket descriptor. Then these descriptors are used to closed the different sockets. Here, with boost, I don't know how make that. Please help me. Thanks..
You are having problems with *basic things*, do ***RTFM*** end experiment. Nobody should do your job for you. --Slava _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I've read all the manual, all the tutorials, all the example and I don't want that someone make the job for me. I came from java world, where all is documented, all is explained in detail...
IMHO, asio is pretty well documented. The problem is that you're trying to find 1-to-1 relationship between asio model and the native C sockets. For this you have to explore asio internals, not only the documentation.

Hi...actually I have a client and a server and both run on the same machine,
but they will be on different machine with different ip address, so I'm trying
to set the Server's Ip address to the client, but it can't work:
I've read that the
basic_endpoint(const boost::asio::ip::address & addr,unsigned short port_num);
Construct an endpoint using a port number and an IP addressso I do the
following:
int port=60000;
char addr[10]="127.0.0.1"; //or another ip address
tcp::socket socket(io_service);
boost::asio::ip::address a = boost::asio::ip::address::from_string(addr);
now I have an "address", I have a port, so I try to build a
basic_endpointboost::asio::ip::basic_endpoint<tcp> bend(const
boost::asio::ip::address & addr, unsigned short port);
finally I need to make an async:connect to that endpoint
socket.
async_connect(bend,boost::bind(connect_handler,boost::asio::placeholders::error,&socket));
but the first parameter of the async_connect is a endpoint and not a
basic_endpoint...
How can I say to the client "connect to X.X.X.X Ip address at the port Y"?
thanks...
________________________________
Da: Igor R
I've read all the manual, all the tutorials, all the example and I don't want that someone make the job for me. I came from java world, where all is documented, all is explained in detail...
IMHO, asio is pretty well documented. The problem is that you're trying to find 1-to-1 relationship between asio model and the native C sockets. For this you have to explore asio internals, not only the documentation. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

but the first parameter of the async_connect is a endpoint and not a basic_endpoint...
erm... I hope you are aware that an endpoint is a basic_endpoint (through inheritance)? boost::asio::ip::tcp::endpoint target( boost::asio::ip::address::from_string( "127.0.0.1" ), 1000 ); socket_.async_connect( target, bind( ... ) ); HtH, Rutger

Hi guys...a simple question..
what happen if there are concurrent write/write(for example async_write_some)
or write/read(for example async_write_some and async_read_some) operation on the
same socket?I have handle this problem or it is automatically handled by boost
functions?
And if I have to send a lot of data, to avoid congestion problem, I need a
buffer?
thank you...
________________________________
Da: Rutger ter Borg
but the first parameter of the async_connect is a endpoint and not a basic_endpoint...
erm... I hope you are aware that an endpoint is a basic_endpoint (through inheritance)? boost::asio::ip::tcp::endpoint target( boost::asio::ip::address::from_string( "127.0.0.1" ), 1000 ); socket_.async_connect( target, bind( ... ) ); HtH, Rutger _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 03/09/2011 11:22 AM, Marco Piacentini wrote:
Hi guys...a simple question.. what happen if there are concurrent write/write(for example async_write_some) or write/read(for example async_write_some and async_read_some) operation on the same socket?I have handle this problem or it is automatically handled by boost functions? And if I have to send a lot of data, to avoid congestion problem, I need a buffer?
thank you...
You have to make sure that no concurrent calls can occur to member functions of the same socket class. This may be achieved by serializing your read/writes/read handlers/write handlers through a strand. In case of large buffers, Asio may split up an async_write() operation into several async_write_some operations (often referred to as "composed operations"). HtH, Cheers, Rutger

I have a simple TCP multiprocess server...inside each child server(each of one
handles distincted connection), I call a list of operation...suppose the
following:
socket.async_read_some(....); //receive a client request
socket.async_write_some(...); //respond to client request
socket.async_write_some(...); //independently of the client request, send
something to the client
Have I use strand,or this situation doesn't cause problems?
I don't use thread...
thanks!!!
________________________________
Da: Rutger ter Borg
Hi guys...a simple question.. what happen if there are concurrent write/write(for example async_write_some) or write/read(for example async_write_some and async_read_some) operation on the same socket?I have handle this problem or it is automatically handled by boost functions? And if I have to send a lot of data, to avoid congestion problem, I need a buffer?
thank you...
You have to make sure that no concurrent calls can occur to member functions of the same socket class. This may be achieved by serializing your read/writes/read handlers/write handlers through a strand. In case of large buffers, Asio may split up an async_write() operation into several async_write_some operations (often referred to as "composed operations"). HtH, Cheers, Rutger _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 03/09/2011 12:14 PM, Marco Piacentini wrote:
I have a simple TCP multiprocess server...inside each child server(each of one handles distincted connection), I call a list of operation...suppose the following:
socket.async_read_some(....); //receive a client request socket.async_write_some(...); //respond to client request
socket.async_write_some(...); //independently of the client request, send something to the client
Have I use strand,or this situation doesn't cause problems? I don't use thread... thanks!!!
Without threads, you don't need a strand (the strand is implicit). But, even without threads, you still would need to make sure that the read or write operation is completed before issueing your next request. So, socket.async_read(...); // OK socket.async_write( ... ); // OK socket.async_read( ... ); // Potential error: 1st async_read may be still in progress Regards, Rutger

ok...then it means that the asyncronous operation needs to be transformed in a
sync operation?
________________________________
Da: Rutger ter Borg
I have a simple TCP multiprocess server...inside each child server(each of one handles distincted connection), I call a list of operation...suppose the following:
socket.async_read_some(....); //receive a client request socket.async_write_some(...); //respond to client request
socket.async_write_some(...); //independently of the client request, send something to the client
Have I use strand,or this situation doesn't cause problems? I don't use thread... thanks!!!
Without threads, you don't need a strand (the strand is implicit). But, even without threads, you still would need to make sure that the read or write operation is completed before issueing your next request. So, socket.async_read(...); // OK socket.async_write( ... ); // OK socket.async_read( ... ); // Potential error: 1st async_read may be still in progress Regards, Rutger _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I've spent 2 hours to try to solve this error
**** Build of configuration Debug for project ServerFork ****
make all
Building target: ServerFork
Invoking: GCC C++ Linker
g++ -L/usr/lib -o"ServerFork" ./ServerFork.o -lboost_thread -lboost_system
./ServerFork.o: In function `__static_initialization_and_destruction_0':
/usr/nuovoboost/boost_asio_1_5_2/boost/system/error_code.hpp:214: undefined
reference to `boost::system::generic_category()'
/usr/nuovoboost/boost_asio_1_5_2/boost/system/error_code.hpp:215: undefined
reference to `boost::system::generic_category()'
/usr/nuovoboost/boost_asio_1_5_2/boost/system/error_code.hpp:216: undefined
reference to `boost::system::system_category()'
./ServerFork.o: In function `error_code':
/usr/nuovoboost/boost_asio_1_5_2/boost/system/error_code.hpp:315: undefined
reference to `boost::system::system_category()'
./ServerFork.o: In function `boost::asio::error::get_system_category()':
/usr/nuovoboost/boost_asio_1_5_2/boost/asio/error.hpp:216: undefined reference
to `boost::system::system_category()'
collect2: ld returned 1 exit status
make: *** [ServerFork] Error 1
I've seen that probably I need to compile the boost system library...but I don't
be able...I'm trying but I don't find a step to step clear and simple
guide...does anyone help me?
________________________________
Da: Igor R
ok...then it means that the asyncronous operation needs to be transformed in a sync operation?
No, it just means that you should "chain" your async. operations in this manner: read -- handler -- read -- handler... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Please, don't reply to unrelated threads, and don't top-post over unrelated messages, as it makes it difficult to understand what you mean.
I've seen that probably I need to compile the boost system library...but I don't be able...I'm trying but I don't find a step to step clear and simple guide...does anyone help me?
Yes, Asio depends on Boost.System. Doesn't this link help: http://www.boost.org/doc/libs/1_46_0/more/getting_started/unix-variants.html...

I'm sorry...ok I've already seen this guide, but:
1)path ok...but "/to" what means?
2)I don't find in my" boost_asio_1_5_2" folder the "bootstrap.sh"
thanks..you're very kind and patient...
________________________________
Da: Igor R
I've seen that probably I need to compile the boost system library...but I don't be able...I'm trying but I don't find a step to step clear and simple guide...does anyone help me?
Yes, Asio depends on Boost.System. Doesn't this link help: http://www.boost.org/doc/libs/1_46_0/more/getting_started/unix-variants.html... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

1)path ok...but "/to" what means?
"path/to/boost_1_46_0" means the path where your unpack boost package. Eg., if you unpack it in Windows into c:/kuku/boost1_46 then it will be the path.
2)I don't find in my" boost_asio_1_5_2" folder the "bootstrap.sh"
I believe, asio development release contains only asio, so I think you have to download and unpack the official boost release first. Then download the asio development release and unpack it directly to the above path, so that newer asio files will overwrite the older ones. Then you've got bootstrap and everything...

Thank you guys..I've solved..you're right, I've to downloaded the complete
archive and then do the rest..
________________________________
Da: Igor R
1)path ok...but "/to" what means?
"path/to/boost_1_46_0" means the path where your unpack boost package. Eg., if you unpack it in Windows into c:/kuku/boost1_46 then it will be the path.
2)I don't find in my" boost_asio_1_5_2" folder the "bootstrap.sh"
I believe, asio development release contains only asio, so I think you have to download and unpack the official boost release first. Then download the asio development release and unpack it directly to the above path, so that newer asio files will overwrite the older ones. Then you've got bootstrap and everything... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

On 2011-03-09 18:51, Marco Piacentini wrote:
I've spent 2 hours to try to solve this error
**** Build of configuration Debug for project ServerFork ****
make all Building target: ServerFork Invoking: GCC C++ Linker g++ -L/usr/lib -o"ServerFork" ./ServerFork.o -lboost_thread -lboost_system
[snip]
./ServerFork.o: In function `boost::asio::error::get_system_category()': /usr/nuovoboost/boost_asio_1_5_2/boost/asio/error.hpp:216: undefined reference to `boost::system::system_category()' collect2: ld returned 1 exit status make: *** [ServerFork] Error 1
I've seen that probably I need to compile the boost system library...but I don't be able...I'm trying but I don't find a step to step clear and simple guide...does anyone help me?
What does "ls -la /usr/lib/libboost_system*" say? Rutger

I have a simple TCP multiprocess server...inside each child server(each of one handles distincted connection), I call a list of operation...suppose the following:
Note also, that only the latest development release supports forking properly: http://think-async.com/Asio/boost_asio_1_5_2/doc/html/boost_asio/examples.ht... (See "Fork" section).

1)Hi guys...I've seen the tutorial and the example, but I don't understand why the function listen() of the acceptor is never called...despite that new connections arrived...how is it possible?
Because some other acceptor member functions and some constructors implicitly call listen(). If you've interested in the implementation details, you can try and step into acceptor implementation and see what happens there exactly.
2)By the following instructions, I create a socket(a connection socket?????or a listening socket???) and then pass it at the acceptor
tcp::socket sock (ioserv); acceptor.accept(sock);
sock is connection socket, acceptor is "listening socket" You can access their native handles (socket handles) by calling native() member function.

thank you Igor, you're very kind...now I understand..bye!
________________________________
Da: Igor R
1)Hi guys...I've seen the tutorial and the example, but I don't understand why the function listen() of the acceptor is never called...despite that new connections arrived...how is it possible?
Because some other acceptor member functions and some constructors implicitly call listen(). If you've interested in the implementation details, you can try and step into acceptor implementation and see what happens there exactly.
2)By the following instructions, I create a socket(a connection socket?????or a listening socket???) and then pass it at the acceptor
tcp::socket sock (ioserv); acceptor.accept(sock);
sock is connection socket, acceptor is "listening socket" You can access their native handles (socket handles) by calling native() member function. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Solved...
I have to use this instruction and all works fine, without using basic_endpoint
boost::asio::ip::tcp::endpoint endpoint=boost::asio::ip::tcp::endpoint(a,port)
________________________________
Da: Igor R
1)Hi guys...I've seen the tutorial and the example, but I don't understand why the function listen() of the acceptor is never called...despite that new connections arrived...how is it possible?
Because some other acceptor member functions and some constructors implicitly call listen(). If you've interested in the implementation details, you can try and step into acceptor implementation and see what happens there exactly.
2)By the following instructions, I create a socket(a connection socket?????or a listening socket???) and then pass it at the acceptor
tcp::socket sock (ioserv); acceptor.accept(sock);
sock is connection socket, acceptor is "listening socket" You can access their native handles (socket handles) by calling native() member function. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (4)
-
Igor R
-
Marco Piacentini
-
Rutger ter Borg
-
Viatcheslav.Sysoltsev@h-d-gmbh.de