本文整理汇总了C++中SocketHandler类的典型用法代码示例。如果您正苦于以下问题:C++ SocketHandler类的具体用法?C++ SocketHandler怎么用?C++ SocketHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SocketHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: rlock
SocketHandler *MythSocketManager::GetConnectionBySocket(MythSocket *sock)
{
QReadLocker rlock(&m_socketLock);
if (!m_socketMap.contains(sock))
return NULL;
SocketHandler *handler = m_socketMap[sock];
handler->UpRef();
return handler;
}
示例2: get_http
std::string get_http(const char *host, int port, const char *request)
{
SocketHandler h;
GetHttp sock(h, request);
sock.Open( host, port );
h.Add(&sock);
while (h.GetCount()) {
h.Select(1, 0);
}
return sock.Response();
}
示例3: server
void server(int & sockfd) {
struct sockaddr_in remote_addr;
socklen_t sin_size = sizeof (struct sockaddr_in);
int client_fd = accept(sockfd, (struct sockaddr *) &remote_addr, &sin_size);
cout << "Received a connection from " << inet_ntoa(remote_addr.sin_addr) << ":" << intToString(remote_addr.sin_port) << endl;
SocketHandler * socket = new SocketHandler(client_fd);
socket->receiveFile("tests/test-recv.bott");
delete socket;
}
示例4: client
void client() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in server;
bzero(&server, sizeof (server));
server.sin_family = AF_INET;
server.sin_port = htons(6636);
server.sin_addr.s_addr = inet_addr("127.0.0.1");
connect(sockfd, (struct sockaddr *) & server, sizeof (server));
SocketHandler * socket = new SocketHandler(sockfd);
socket->sendFile("tests/test.bott");
delete socket;
}
示例5: sizeof
// ----------------------------------------
void BindedHandler::pollRead() {
static socklen_t len = sizeof(struct sockaddr_in);
sockaddr_in address;
// Check limit
if (sockets.size() >= maxConn) {
Common::Logger::critical("Too many connections on Port %d", port);
acceptConnections(0);
return;
}
// Try to accept connection
int clientFd = ::accept(socketFd, (sockaddr *) &address, &len);
char buf[30];
Tools::IP::sprintfAddress(buf, address);
Common::Logger::debug("New connection from %s", buf);
// Error?
if (clientFd == -1) {
if (errno == EAGAIN) {
return;
}
else if (errno == EMFILE) {
perror("Error on accept");
acceptConnections(0);
return;
}
else {
perror("Error on accept");
return;
}
}
SocketHandler* userData = newSocketHandler(address);
// Non allowed address?
if (userData == NULL) {
Common::Logger::critical("Paff! %s", buf);
close(clientFd);
return;
}
// Add to epoll
userData->socketFd = clientFd;
((BufferedSocketHandler*) userData)->parentHandler = this;
userData->socketAddress = address.sin_addr.s_addr;
Tools::IP::sprintfAddress(userData->socketAddressStr, address);
sockets.push_front(userData);
userData->registerEvents(10);
}
示例6: main
int main(int argc, char *argv[])
{
SocketHandler h;
ListenSocket<IOSocket> l(h);
l.Bind(12344);
h.Add(&l);
IOSocket sock(h);
sock.Open("192.168.7.4", 12344);
h.Add(&sock);
while (!quit)
{
h.Select(1, 0);
}
}
示例7: MythSocket
bool OutboundRequestHandler::DoConnectToMaster(void)
{
if (m_socket)
m_socket->DecrRef();
m_socket = new MythSocket(-1, m_parent);
QString server = gCoreContext->GetMasterServerIP();
QString hostname = gCoreContext->GetMasterHostName();
int port = gCoreContext->GetMasterServerPort();
if (!m_socket->ConnectToHost(server, port))
{
LOG(VB_GENERAL, LOG_ERR, "Failed to connect to master backend.");
m_socket->DecrRef();
m_socket = NULL;
return false;
}
#ifndef IGNORE_PROTO_VER_MISMATCH
if (!m_socket->Validate())
{
LOG(VB_GENERAL, LOG_NOTICE, "Unable to confirm protocol version with backend.");
m_socket->DecrRef();
m_socket = NULL;
return false;
}
#endif
if (!AnnounceSocket())
{
LOG(VB_GENERAL, LOG_NOTICE, "Announcement to upstream master backend failed.");
m_socket->DecrRef();
m_socket = NULL;
return false;
}
SocketHandler *handler = new SocketHandler(m_socket, m_parent, hostname);
handler->BlockShutdown(true);
handler->AllowStandardEvents(true);
handler->AllowSystemEvents(true);
m_parent->AddSocketHandler(handler); // register socket for reception of events
handler->DecrRef(); // drop local instance in counter
handler = NULL;
LOG(VB_GENERAL, LOG_NOTICE, "Connected to master backend.");
return true;
}
示例8: main
int main()
{
SocketHandler h;
ListenSocket<ServerSocket> l(h);
if (l.Bind(40001,10))
{
exit(-1);
}
h.Add(&l);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
示例9: main2
int main2()
{
SocketHandler h;
ListenSocket<ServerSocket> ll(h);
if (ll.Bind(443))
{
return -1;
}
h.Add(&ll);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
示例10: main
int main(int argc,char *argv[])
{
if (argc > 1)
{
SocketHandler h;
ClientSocket cc(h,argv[1]);
cc.Open("127.0.0.1",40001);
// Add after Open
h.Add(&cc);
h.Select(1,0);
while (h.GetCount())
{
h.Select(1,0);
}
}
}
示例11: SetSlaveHandler
void Socket::SocketThread::Run()
{
SocketHandler h;
h.SetSlave();
h.Add(m_socket);
m_socket -> SetSlaveHandler(&h);
m_socket -> OnDetached();
while (h.GetCount() && IsRunning())
{
h.Select(0, 500000);
}
// m_socket now deleted oops
// yeah oops m_socket delete its socket thread, that means this
// so Socket will no longer delete its socket thread, instead we do this:
SetDeleteOnExit();
}
示例12: main
int main(int argc, char *argv[])
{
std::string host = argc > 1 ? argv[1] : "www.alhem.net";
int port = argc > 2 ? atoi(argv[2]) : 80;
SocketHandler h;
for (int i = 1; i < 255; i++)
{
char host[40];
sprintf(host, "10.170.23.%d", i);
tSocket *p = new tSocket(h, host, 23);
h.Add(p);
}
while (h.GetCount())
{
h.Select(1, 0);
}
}
示例13: run
void run ()
{
SocketHandler h;
// Launch the RA listener socket
ListenSocket<RASocket> RAListenSocket (h);
bool usera = sConfig.GetBoolDefault ("Ra.Enable", false);
if (usera)
{
port_t raport = sConfig.GetIntDefault ("Ra.Port", 3443);
std::string stringip = sConfig.GetStringDefault ("Ra.IP", "0.0.0.0");
ipaddr_t raip;
if (!Utility::u2ip (stringip, raip))
sLog.outError ("MaNGOS RA can not bind to ip %s", stringip.c_str ());
else if (RAListenSocket.Bind (raip, raport))
sLog.outError ("MaNGOS RA can not bind to port %d on %s", raport, stringip.c_str ());
else
{
h.Add (&RAListenSocket);
sLog.outString ("Starting Remote access listner on port %d on %s", raport, stringip.c_str ());
}
}
// Socket Selet time is in microseconds , not miliseconds!!
uint32 socketSelecttime = sWorld.getConfig (CONFIG_SOCKET_SELECTTIME);
// if use ra spend time waiting for io, if not use ra ,just sleep
if (usera)
{
while (!World::IsStopped())
{
h.Select (0, socketSelecttime);
checkping ();
}
}
else
{
while (!World::IsStopped())
{
ACE_Based::Thread::Sleep(static_cast<unsigned long> (socketSelecttime / 1000));
checkping ();
}
}
}
示例14: main
int main(int argc, char *argv[])
{
try
{
SocketHandler h;
if (argc > 1 && !strcmp(argv[1], "-server"))
{
ListenSocket<tSocket> l(h);
l.Bind(4443);
h.Add(&l);
while (h.GetCount())
{
h.Select(1, 0);
}
}
else
{
std::string host = argc > 1 ? argv[1] : "www.alhem.net";
tSocket sock(h, host);
h.Add(&sock);
while (h.GetCount())
{
h.Select(1, 0);
}
}
}
catch (const Exception& e)
{
printf("%s\n", e.ToString().c_str());
}
}
示例15: Run
void ResolvServer::Run()
{
// StdoutLog log;
SocketHandler h;
ListenSocket<ResolvSocket> l(h);
if (l.Bind("127.0.0.1", m_port))
{
return;
}
h.Add(&l);
m_ready = true;
while (!m_quit && IsRunning() )
{
h.Select(0, 500000);
}
SetRunning(false);
}