visual c++ - Problem with Boost Asio asynchronous connection using C++ in Windows -


using ms visual studio 2008 c++ windows 32 (xp brand), try construct pop3 client managed modeless dialog box.

te first step create persistent object -say pop3- boost.asio stuff asynchronous connections, in wm_initdialog message of dialog-box-procedure. like:

case wm_initdialog:     return (inipop3dlg (hdlg, lparam)); 

here assume inipop3dlg() create pop3 heap object -say pointed out pop3p-. connect remote server, , session initiated client’s id , password (user , pass commands). here assume server in transaction state.

then, in response user input, dialog-box-procedure, call appropriate function. say:

case ids_total: //  how many emails in server     total (pop3p);     return false; case ids_detail:   // date, sender , subject each email in server     detail (pop3p);     return false; 

note total() uses pop3’s stat command how many emails in server, while detail() uses 2 commands consecutively; first stat total , loop command retrieve content of each message.

as aside: detail() , total() share same subroutines -the stat handle routine-, , when finished, both leaves session as-is. is, without closing connection; socket remains opened server in transaction state.

when option selected first time, things run expected, obtaining desired results. when making second chance, connection hangs.

a closer inspection show first time statement

socket_.get_io_service().run(); 

is used, never ends.

note asynchronous write , read routines uses same io_service, , each routine uses socket_.get_io_service().reset() prior run()

not r/w operations uses same timer, reseted 0 wait after each operation completed:

dtimer_.expires_from_now (boost::posix_time::seconds(0)); 

i suspect problem in io_service or in timer, , fact subsequent executions occurs in different load of routine.

as first approach problem, hope bring light in it, prior more detailed exposition of -very few , simple- routines involved.

have looked @ asio examples , studied them? there several asynchronous examples should understand basic control flow. pay particular importance main event loop started invoking io_service::run, it's important understand control not expected return caller until io_service has no more remaining work do.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -