Socket::~Socket() { TRACE("destroying. fd:%d, local(%s:%d)", fd_, localIP().c_str(), localPort()); if (fd_ >= 0) ::close(fd_); }
Socket::Socket(struct ev_loop* loop, int fd, int af) : loop_(loop), watcher_(loop), timer_(loop), startedAt_(ev_now(loop)), lastActivityAt_(ev_now(loop)), fd_(fd), addressFamily_(af), secure_(false), state_(Operational), mode_(None), tcpCork_(false), remoteIP_(), remotePort_(0), localIP_(), localPort_(), callback_(nullptr), callbackData_(0) { #ifndef NDEBUG setLogging(false); static std::atomic<unsigned long long> id(0); setLoggingPrefix("Socket(%d, %s:%d)", ++id, remoteIP().c_str(), remotePort()); #endif TRACE("created. fd:%d, local(%s:%d)", fd_, localIP().c_str(), localPort()); watcher_.set<Socket, &Socket::io>(this); timer_.set<Socket, &Socket::timeout>(this); }
std::string Socket::local() const { char buf[512]; size_t n; switch (addressFamily_) { case AF_INET: n = snprintf(buf, sizeof(buf), "%s:%d", localIP().c_str(), localPort()); break; case AF_INET6: n = snprintf(buf, sizeof(buf), "[%s]:%d", localIP().c_str(), localPort()); break; default: n = snprintf(buf, sizeof(buf), "%s", localIP().c_str()); break; } return std::string(buf, n); }
struct address * verify(struct letter *let, struct domain *dom, char *p, int flags, int *reason) { char *e = p + strlen(p); int bad = 0; struct address *ret; extern char *addr(char*,int*); struct iplist mxes; int i; while ( (e > p) && (isspace(e[-1]) || e[-1] == '\r' || e[-1] == '\n') ) --e; if (*e) *e = 0; if ((e > p) && (ret = mkaddress(addr(p, &bad))) ) { if (ret->domain) { ret->local = 0; /* check that there is an mx (or A record) for the mail domain; * if that fails we fail unless verify_from is off and it's * a MAIL FROM:<> address */ if ( (getMXes(ret->domain, 1, &mxes) > 0) ) { for (i=0; i < mxes.count; i++) if ( localIP(let->env, &mxes.a[i] ) ) { /* we are a legitimate mx for this address. */ ret->local = 1; if ( (i == 0) || !(let->env->mxpool) ) { /* If we're not mxpooling, we handle mail for * this domain locally, but if we are mxpooling * we only handle the mail locally if we're the * best mx for the domain */ ret->deliver_here = 1; ret->dom = getdomain(ret->domain); } break; } freeiplist(&mxes); } else if ( !okayanyhow(let->env,flags) ) { if (reason) *reason = V_NOMX; freeaddress(ret); return 0; } } else { ret->deliver_here = ret->local = 1; ret->dom = dom; } if (ret->deliver_here && (!userok(let,ret)) && (flags & VF_USER) ) { if (reason) *reason = V_WRONG; freeaddress(ret); return 0; } return ret; } if (reason) { *reason = bad ? V_BOGUS : V_ERROR; } return 0; }