b***i 发帖数: 3043 | 1 有一个类,TCPServer{
public: TCPServer(asio::io_service& io_service, const tcp::endpoint& listen_
endpoint){...}
private:
asio::io_service& io_service_;
asio::ip::tcp::acceptor acceptor_;
TCPListener listener_;
};
这个类是boost的一个例子。我的代码需要三个变量,放在TCPServerManager里面,为
简单起见,我定义三个static变量。
TCPServerManager{
static TCPServer eth0, eth1, wifi;
static void start(){...}
};
那么,在start里面,我根据boost的例子,用TCPServer s(io_service, listen_
endpoint);定义了一个变量。怎么把这个变量变成我的eth0,eth1, wifi呢?
在定义eth0的那个地方,需要的listen_endpoint还没有好,就... 阅读全帖 |
|
n**n 发帖数: 626 | 2 1) Can we use TCPServer* eth0 instead of TCPServer eth0? then maybe we can
create and record heap memory object in start() after "listen_endpoint". I
don't see the need of keeping a TCPServer object inside.
2) Why should we use static member TCPServer eth0 here? Are there many
TCPServerManager objects? |
|
n**n 发帖数: 626 | 3 I don't quite understand the relation between singleton manager object
and static member variables.
singleton of manager class is usually implemented using a getServer() method
, while static member variable is more like a global variable under a class
name.
btw, I never see such 新潮.
[在 bihai (学得不好) 的大作中提到:]
:有一个类,TCPServer{
:public: TCPServer(asio::io_service& io_service, const tcp::endpoint&
listen_endpoint){...}
:........... |
|
b***i 发帖数: 3043 | 4 我的代码是基于ASIO的TCPServer的一个例子,是挺容易理解的,如下,是只要有
connection来,就接受连接。
void start_accept() {
tcp_session_ptr new_session(new TCP_Session(io_service_));
acceptor_.async_accept(new_session->socket(),
std::bind(&TCPServer::handle_accept, this, new_session, std::
placeholders::_1));
}
void handle_accept(tcp_session_ptr session, const asio::error_code& ec) {
if (!ec)
session->start();
start_accept();
}
然后,在session里面我是这样的,先处理来的包,再start_rea... 阅读全帖 |
|
w*******e 发帖数: 285 | 5 我原来的一个简单的tcpserver是每次有连接就创建一个新的thread,就像这样
Socket connectionSocket = serverSocket.accept();
new myThread(connectionSocket, CoreDB).start();
现在想改成threadpool,本来想自己写,但是发现有一个非常简单的
ThreadPoolExecutor,用起来就象这样
Socket connectionSocket = serverSocket.accept();
threadPoolExecutor.execute(new myThread(connectionSocket));
help里面说ThreadPoolExecutor有最小count和max count,thread数量低于min count的
时候每次都创建新的thread,在min count和max count之间只有queue满的时候才会创建
新的thread,如果已经达到max count而且queue也满了就会转给rejecthandler.
我不太理解的是概念上的问题,我的 |
|
r****t 发帖数: 10904 | 6 gst-launch filesrc location=1.MPG ! decodebin ! video/x-raw-yuv, width=640,
height=480,framerate=5/1 ! ffmpegcolorspace ! jpegenc ! multipartmux !
tcpserversink host=192.168.2.1 port=5000
streaming 我自己只试过 shout2send, 不过 tcpserver 应该差不太多。 |
|