Source: http://blog.csdn.net/pud_zha/article/details/37561011
Work is a small helper class that supports only constructors and destructors. (There is also a get_io_service returned by the associated Io_service) when constructing a work,
Let's take a look at the elegant exit, but there are still some imperfections. When receiving the exit signal, io_service is directly disabled, instead of closing all connections and then exiting. In fact, three things should be done in order:
1.
As mentioned in the libev demo, how does epoll work? to better reach the underlying layer, we use epoll APIs to design an echoserver.
The client code is the same as the previous one.
Echoserver. cpp is as follows:
#include #include
/////////////////////////// //////////// ASIO synchronization socket connection example // # include # include # include # include using namespace boost; typedef boost: ASIO: io_service ioservice; typedef boost: ASIO: IP: TCP; bool flag = true;
Start with newlispProgramTest, initiate a connection, send a correct character 'a', connect continuously, then send an error character, disconnect.
The test script is as follows:
(Define (quit-for-error) (println (net-error) (exit) (set 'socket (
Document directory
Commands in FTP
Someone else's code was slightly modified. Boost1.50 and vs2008 can be compiled successfully.
----------- Test_ftp.cpp ---------------
// Ftp_asio.cpp: defines the entry point of the console application. ////
The previous article is very simple and easy to understand. However, in C ++, you still need to encapsulate the code that can be used in multiple projects.
The following cancels the global variable, creates a server class, provides the run function,
Newlisp provides a simple method for me to create multiple processes. The following program creates 10 processes, each of which sends several 'A' and finally sends a 'q '.
(define (quit-for-error) ((println (net-error)) (exit)))(define (send-test)
ASIO.ASIO: io_service;TCP: Socket socket (io_service );Boost: ASIO: async_connect (socket, server_address, connect_handler );Io_service.run ();Although there are only four lines of code, there are actually a lot of complicated internal tasks, blocking a lot of details to make it easy to use. First, let's take a look at the first line of code. The first line of code defines a core
////Sync_client.cpp// ~~~~~~~~~~~~~~~//HTTP client, synchronizing//Copyright (c) 2003-2013 Christopher M. Kohlhoff (Chris at kohlhoff dot com)////distributed under the Boost software License, Version 1.0. (See accompanying//file license_1_0.txt or copy atHttp://www.boost.org/LICENSE_1_0.txt)//#include#include#include#includestring>#includeusingboost::asio::ip::tcp;intMainintargcChar*argv[]) { Try { if(
(Original) Open the fog to see the moon-analyze the proactor mode in asio (2), asioproactor
In the previous blog, we mentioned that asynchronous requests are forwarded from the upper layer to the win_iocp_socket_service object at the bottom of the service layer, which forwards requests to the Operating System (Calling windows APIs ), how does the operating system return the result to the application after processing the asynchronous request? Here, it
Ace is a very mature middleware product. It is an adaptive communication environment, but it is too ambitious. There are a bunch of design patterns, and the architecture is layer after layer. It is a little difficult for beginners.
ASIO is a basic asynchronous Io library developed by boost. It encapsulates socket and simplifies socket-based
Program Development.
Recently analyzed
();}
3Connect to the remote server
After receiving data from the client, the proxy server is connected to the remote server.
View code
// Receive data from the client Void Start_downstream_receive (){ // If the client data is received, the link to the server is triggered. Downstream_socket _. async_receive_from (boost: ASIO: buffer (downstream_data _, max_data_length), downstream_remoteudpe
// Testboost. cpp: defines the console applicationProgram.//
# Include "stdafx. H"# Include "stdio. H"# Include # Include # Include "stringutil. H"# Include # Include # Include # Include # Include # Include # Include # Include # Include
Wchar_t g_szsourcefile [2, 256];Wchar_t g_szdestfile [2, 256];
//////////////////////////////////////// ////////////////////////////////////// Serial port Test
Typedef boost: System: error_code boost_error_cod
Http://www.cnblogs.com/zhiranok/archive/2011/12/12/boost_asio.html on front side
As I mentioned, to address the problems encountered in boost ASIO, encapsulate ASIO with the following goals:
1. Create a socket and acceptor and no longer construct io_service by yourself. Because the objects in ASIO need to save the
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.