本文整理汇总了C++中Handler函数的典型用法代码示例。如果您正苦于以下问题:C++ Handler函数的具体用法?C++ Handler怎么用?C++ Handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Handler
bool Socket::SetSoKeepalive(bool x)
{
#ifdef SO_KEEPALIVE
int optval = x ? 1 : 0;
if (setsockopt(GetSocket(), SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) == -1)
{
Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_KEEPALIVE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
return false;
}
return true;
#else
Handler().LogError(this, "socket option not available", 0, "SO_KEEPALIVE", LOG_LEVEL_INFO);
return false;
#endif
}
示例2: Handler
bool Socket::SetSoBroadcast(bool x)
{
#ifdef SO_BROADCAST
int optval = x ? 1 : 0;
if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval)) == -1)
{
Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BROADCAST)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
return false;
}
return true;
#else
Handler().LogError(this, "socket option not available", 0, "SO_BROADCAST", LOG_LEVEL_INFO);
return false;
#endif
}
示例3: logdetail
void ControlSocket::OnAccept(void)
{
logdetail("ControlSocket: Incoming connection from %s:%u [host:%s]",GetRemoteAddress().c_str(),GetRemotePort(),GetRemoteHostname().c_str());
// must perform some crappy ptr conversion here, doesnt want to typecast SocketHandler -> ControlSocketHandler directly
SocketHandler& hnd = Handler();
ControlSocketHandler *chnd = static_cast<ControlSocketHandler*>(&hnd);
_instance = chnd->GetInstance();
DEBUG(logdebug("ControlSocket: setting instance = %X",_instance));
// accept only connections from one host for now, if set
if(_instance->GetConf()->rmcontrolhost.length()
&& !(GetRemoteAddress() == _instance->GetConf()->rmcontrolhost || GetRemoteHostname() == _instance->GetConf()->rmcontrolhost))
{
logdetail("ControlSocket: connection rejected. closing.");
SetCloseAndDelete(true);
return;
}
SendTelnetText(_instance->GetScripts()->variables.Get("@version"));
if(_instance->GetConf()->rmcontrolpass.size())
{
SendTelnetText("Authentication?");
}
_ok = true;
}
示例4: requestRouterState
AsyncValue<Handler> Server::routeDynamicRequestFromFile(String path) {
auto lp=mgr->loadPage(*p,root,path);
if(lp) return Handler(&dynamicHandler,lp());
requestRouterState* st=new requestRouterState();
lp.wait(st);
return Future<Handler>(&st->cb);
}
示例5: interval
int
Input_Task::add_timer (void *argument)
{
u_long useconds = *reinterpret_cast<int *> (argument);
ACE_Time_Value interval (useconds / usecs_,
useconds % usecs_);
ACE_Time_Value expire_at = ACE_OS::gettimeofday () + interval;
Handler *h;
ACE_NEW_RETURN (h,
Handler (expire_at),
-1);
int id = queue_->schedule (h, 0, expire_at);
if (id == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"schedule failed"),
-1);
// We store the id into the handler, this is only used to produce
// nicer messages.
h->set_id (id);
ACE_OS::printf ("scheduling timer %d\n",
id);
return 0;
}
示例6: sctp_recvmsg
void SctpSocket::OnRead()
{
/*
int sctp_recvmsg(int sd, void * msg, size_t * len,
struct sockaddr * from, socklen_t * fromlen,
struct sctp_sndrcvinfo * sinfo, int * msg_flags);
DESCRIPTION
sctp_recvmsg is a wrapper library function that can be used to receive a message from a socket while using the advanced
features of SCTP. sd is the socket descriptor on which the message pointed to by msg of length len is received.
If from is not NULL, the source address of the message is filled in. The argument fromlen is a value-result parameter.
initialized to the size of the buffer associated with from , and modified on return to indicate the actual size of the
address stored.
sinfo is a pointer to a sctp_sndrcvinfo structure to be filled upon receipt of the message. msg_flags is a pointer to a
integer that is filled with any message flags like MSG_NOTIFICATION or MSG_EOR.
*/
struct sockaddr sa;
socklen_t sa_len = 0;
struct sctp_sndrcvinfo sinfo;
int flags = 0;
int n = sctp_recvmsg(GetSocket(), m_buf, SCTP_BUFSIZE_READ, &sa, &sa_len, &sinfo, &flags);
if (n == -1)
{
Handler().LogError(this, "SctpSocket", Errno, StrError(Errno), LOG_LEVEL_FATAL);
SetCloseAndDelete();
}
else
{
OnReceiveMessage(m_buf, n, &sa, sa_len, &sinfo, flags);
}
}
示例7: Handler
void HttpPutSocket::SetFile(const std::string& file)
{
//struct stat st;
// Added by Amir Krifa
std::ifstream f;
f.open(file.c_str(), std::ios_base::binary | std::ios_base::in);
//if (!f.good() || f.eof() || !f.is_open()) { return 0; }
if (!f.good() || f.eof() || !f.is_open())
{
Handler().LogError(this, "SetFile", Errno, StrError(Errno), LOG_LEVEL_FATAL);
SetCloseAndDelete();
}else
{
f.seekg(0, std::ios_base::beg);
std::ifstream::pos_type begin_pos = f.tellg();
f.seekg(0, std::ios_base::end);
m_filename = file;
m_content_length = static_cast<off_t>(f.tellg() - begin_pos);
}
//if (!stat(file.c_str(), &st))
//{
// m_filename = file;
// m_content_length = st.st_size;
//}
//else
//{
// Handler().LogError(this, "SetFile", Errno, StrError(Errno), LOG_LEVEL_FATAL);
// SetCloseAndDelete();
//}
}
示例8: read
void StdinLine::OnRead()
{
char buf[m_bufsize];
int n = read(GetSocket(), buf, m_bufsize - 1); //recv(0, buf, 1000, 0);
if (n == -1)
{
Handler().LogError(this, "OnRead", errno, strerror(errno), LOG_LEVEL_FATAL);
SetCloseAndDelete();
return;
}
for (size_t i = 0; i < (size_t)n; i++)
{
switch (buf[i])
{
case 13: // ignore
break;
case 10:
OnLine(m_line);
m_line = "";
break;
default:
m_line += buf[i];
}
}
}
示例9: OnEvent
void OnEvent(int id) {
if (id != m_id)
{
printf("ID MISMATCH!\n");
exit(-1);
}
if (!quit)
{
lSocket *p = new lSocket(Handler());
p -> SetDeleteByHandler();
p -> Open(HOST, PORT);
Handler().Add(p);
}
static_cast<evHandler&>(Handler()).SetQuit( quit );
SetCloseAndDelete();
}
示例10: Handler
// ===========================================================================
// method definitions
// ===========================================================================
// ---------------------------------------------------------------------------
// static methods
// ---------------------------------------------------------------------------
void
NIImporter_ITSUMO::loadNetwork(const OptionsCont& oc, NBNetBuilder& nb) {
// check whether the option is set (properly)
if (!oc.isSet("itsumo-files")) {
return;
}
/* Parse file(s)
* Each file is parsed twice: first for nodes, second for edges. */
std::vector<std::string> files = oc.getStringVector("itsumo-files");
// load nodes, first
Handler Handler(nb);
for (std::vector<std::string>::const_iterator file = files.begin(); file != files.end(); ++file) {
// nodes
if (!FileHelpers::exists(*file)) {
WRITE_ERROR("Could not open itsumo-file '" + *file + "'.");
return;
}
Handler.setFileName(*file);
PROGRESS_BEGIN_MESSAGE("Parsing nodes from itsumo-file '" + *file + "'");
if (!XMLSubSys::runParser(Handler, *file)) {
return;
}
PROGRESS_DONE_MESSAGE();
}
}
示例11: strlen
template<> bool Config<const char *>::Set(const char *newval)
{
if( m_current == newval )
return true;
if( m_current && newval && 0==strcmp(newval, m_current) )
return true;
if( !Locked() && Valid(newval) ){
size_t len;
char *tmp;
if( m_current ){
delete []m_current;
m_current = (const char *)0;
}
if( newval ){
len = strlen(newval);
if( MaxLen() && len > MaxLen() ) len = MaxLen();
if( !(tmp = new char[len + 1]) ) return false;
strncpy(tmp, newval, len);
tmp[len] = '\0';
m_current = tmp;
}
Handler();
if(*cfg_verbose)
CONSOLE.Debug("Config: %s = \"%s\"", Tag(), m_current ? m_current : "");
return true;
}
return false;
}
示例12: Handler
void UdpSocket::SetMulticastDefaultInterface(in6_addr a, int if_index)
{
if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_IF, &if_index, sizeof(if_index)) == -1)
{
Handler().LogError(this, "SetMulticastDefaultInterface(ipv6)", Errno, StrError(Errno), LOG_LEVEL_WARNING);
}
}
示例13: CreateConnection
void UdpSocket::SetMulticastHops(int hops)
{
if (GetSocket() == INVALID_SOCKET)
{
CreateConnection();
}
if (!IsIpv6())
{
Handler().LogError(this, "SetMulticastHops", 0, "Ipv6 only", LOG_LEVEL_ERROR);
return;
}
if (setsockopt(GetSocket(), IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&hops, sizeof(int)) == -1)
{
Handler().LogError(this, "SetMulticastHops", Errno, StrError(Errno), LOG_LEVEL_WARNING);
}
}
示例14: Attach
int UdpSocket::Bind(SocketAddress& ad, int range)
{
if (GetSocket() == INVALID_SOCKET)
{
Attach(CreateSocket(ad.GetFamily(), SOCK_DGRAM, "udp"));
}
if (GetSocket() != INVALID_SOCKET)
{
SetNonblocking(true);
int n = bind(GetSocket(), ad, ad);
int tries = range;
while (n == -1 && tries--)
{
ad.SetPort(ad.GetPort() + 1);
n = bind(GetSocket(), ad, ad);
}
if (n == -1)
{
Handler().LogError(this, "bind", Errno, StrError(Errno), LOG_LEVEL_FATAL);
SetCloseAndDelete();
#ifdef ENABLE_EXCEPTIONS
throw Exception("bind() failed for UdpSocket, port:range: " + Utility::l2string(ad.GetPort()) + ":" + Utility::l2string(range));
#endif
return -1;
}
m_bind_ok = true;
m_port = ad.GetPort();
return 0;
}
return -1;
}
示例15: fwrite
void HttpClientSocket::OnData(const char *buf,size_t len)
{
if (m_fil)
{
m_fil -> fwrite(buf, 1, len);
}
else
if (m_data_ptr)
{
if (m_content_ptr + len > m_data_size)
{
Handler().LogError(this, "OnData", -1, "content buffer overflow", LOG_LEVEL_ERROR);
}
else
{
memcpy(m_data_ptr + m_content_ptr, buf, len);
}
}
m_content_ptr += len;
if (m_content_ptr == m_content_length && m_content_length)
{
if (m_fil)
{
m_fil -> fclose();
delete m_fil;
m_fil = NULL;
}
m_b_complete = true;
OnContent();
if (m_b_close_when_complete)
{
SetCloseAndDelete();
}
}
}