Ip Address::ip(Ip ip) { #ifdef WINDOWS unsigned long address = inet_addr(ip.c_str()); if (address == INADDR_NONE) { stringstream error; error << "[ip] with [ip=" << ip << "] Invalid ip address provided"; throw SocketException(error.str()); } else { this->sin_addr.S_un.S_addr = address; } #else if (inet_aton(ip.c_str(), &this->sin_addr) == 0) { stringstream error; error << "[ip] with [ip=" << ip << "] Invalid ip address provided"; throw SocketException(error.str()); } #endif return this->ip(); }
void LinkScheduler::on_ip_schedule(evutil_socket_t sock, short event, void *arg) { IpContext *ipContext = (IpContext*)arg; HttpProcessor *httpProcessor = ipContext->linkTable->getLinkScheduler()->_httpProcessor; Ip ip; Site site; UrlContext *urlContext = NULL; bool isIpContextObsolete = ipContext->linkTable->select(ipContext, ip, site, urlContext); LOG_F(DEBUG, "pop ip=%s site=%s url=%s urlContext:%p", ip.c_str(), site.c_str(), urlContext->url.c_str(), urlContext); httpProcessor->pushConnectQueue(urlContext); // select()可能delete掉ipContext if (!isIpContextObsolete) { struct event *ipScheduleEvent = ipContext->ipScheduleEvent; struct timeval t = {ipContext->scheduleInterval, 0 }; evtimer_add(ipScheduleEvent, &t); } }