* | Inspire Internet Relay Chat Daemon |
* +------------------------------------+
*
- * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
- *
- * Written by Craig Edwards, Craig McLure, and others.
+ * InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ * See: http://www.inspircd.org/wiki/index.php/Credits
+ *
* This program is free but copyrighted software; see
* the file COPYING for details.
*
this->fd = -1;
this->state = I_ERROR;
this->OnError(I_ERR_SOCKET);
- this->Instance->Log(DEBUG,"OpenTCPSocket() error");
return;
}
else
{
if (!SI->BindSocket(this->fd,this->client,this->server,aport,(char*)ipaddr.c_str()))
{
- this->Instance->Log(DEBUG,"BindSocket() error %s",strerror(errno));
this->Close();
this->fd = -1;
this->state = I_ERROR;
this->OnError(I_ERR_NOMOREFDS);
}
}
- this->Instance->Log(DEBUG,"New socket now in I_LISTENING state");
return;
}
}
if (insp_aton(host,&addy) < 1)
{
- this->Instance->Log(DEBUG,"You cannot pass hostnames to InspSocket, resolve them first with Resolver!");
+ this->Instance->Log(DEBUG,"BUG: Hostname passed to InspSocket, rather than an IP address!");
this->Close();
this->fd = -1;
this->state = I_ERROR;
}
else
{
- this->Instance->Log(DEBUG,"No need to resolve %s",this->host);
strlcpy(this->IP,host,MAXBUF);
timeout_val = maxtime;
this->DoConnect();
{
insp_inaddr n;
ConfigReader Conf(this->Instance);
-
- this->Instance->Log(DEBUG,"In InspSocket::BindAddr()");
for (int j =0; j < Conf.Enumerate("bind"); j++)
{
std::string Type = Conf.ReadValue("bind","type",j);
if (insp_aton(IP.c_str(),&n) > 0)
{
- this->Instance->Log(DEBUG,"Found an IP to bind to: %s",IP.c_str());
#ifdef IPV6
s.sin6_addr = n;
s.sin6_family = AF_FAMILY;
#endif
if (bind(this->fd,(struct sockaddr*)&s,sizeof(s)) < 0)
{
- this->Instance->Log(DEBUG,"Cant bind()");
this->state = I_ERROR;
this->OnError(I_ERR_BIND);
this->fd = -1;
return false;
}
- this->Instance->Log(DEBUG,"bind() reports outbound fd bound to ip %s",IP.c_str());
return true;
}
- else
- {
- this->Instance->Log(DEBUG,"Address '%s' was not an IP address",IP.c_str());
- }
}
}
}
- this->Instance->Log(DEBUG,"Found no suitable IPs to bind, binding INADDR_ANY");
return true;
}
bool InspSocket::DoConnect()
{
- this->Instance->Log(DEBUG,"In DoConnect()");
if ((this->fd = socket(AF_FAMILY, SOCK_STREAM, 0)) == -1)
{
- this->Instance->Log(DEBUG,"Cant socket()");
this->state = I_ERROR;
this->OnError(I_ERR_SOCKET);
return false;
return false;
}
- this->Instance->Log(DEBUG,"Part 2 DoConnect() %s",this->IP);
insp_aton(this->IP,&addy);
#ifdef IPV6
addr.sin6_family = AF_FAMILY;
{
if (errno != EINPROGRESS)
{
- this->Instance->Log(DEBUG,"Error connect() %d: %s",this->fd,strerror(errno));
this->OnError(I_ERR_CONNECT);
this->Close();
this->state = I_ERROR;
}
this->SetQueues(this->fd);
}
- this->Instance->Log(DEBUG,"Returning true from InspSocket::DoConnect");
return true;
}
{
Instance->Config->GetIOHook(this)->OnRawSocketClose(this->fd);
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+ Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
this->OnClose();
{
MOD_RESULT = Instance->Config->GetIOHook(this)->OnRawSocketRead(this->fd,this->ibuf,sizeof(this->ibuf),result2);
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- Instance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
+ Instance->Log(DEFAULT,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
if (MOD_RESULT < 0)
{
{
int err = errno;
if (err == EAGAIN)
- {
return "";
- }
else
- {
- if (!n)
- this->Instance->Log(DEBUG,"EOF or error on socket: EOF");
- else
- this->Instance->Log(DEBUG,"EOF or error on socket: %s",strerror(err));
return NULL;
- }
}
}
void InspSocket::MarkAsClosed()
{
- this->Instance->Log(DEBUG,"Marked as closed");
}
// There are two possible outcomes to this function.
{
try
{
- Instance->Log(DEBUG,"To write: %s", outbuffer[0].c_str());
int result = Instance->Config->GetIOHook(this)->OnRawSocketWrite(this->fd, outbuffer[0].c_str(), outbuffer[0].length());
if (result > 0)
{
errno = EAGAIN;
}
}
- else if ((result == -1) && (errno != EAGAIN))
+ else if (((result == -1) && (errno != EAGAIN)) || (result == 0))
{
- this->Instance->Log(DEBUG,"Write error on socket: %s",strerror(errno));
this->OnError(I_ERR_WRITE);
this->state = I_ERROR;
this->Instance->SE->DelFd(this);
return true;
}
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- Instance->Log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
+ Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
return true;
}
}
}
else if ((result == -1) && (errno != EAGAIN))
{
- this->Instance->Log(DEBUG,"Write error on socket: %s",strerror(errno));
this->OnError(I_ERR_WRITE);
this->state = I_ERROR;
this->Instance->SE->DelFd(this);
void SocketTimeout::Tick(time_t now)
{
if (ServerInstance->SE->GetRef(this->sfd) != this->sock)
- {
- ServerInstance->Log(DEBUG,"Our socket has been deleted before the timeout was reached.");
return;
- }
if (this->sock->state == I_CONNECTING)
{
- ServerInstance->Log(DEBUG,"Timed out, current=%lu",now);
// for non-listening sockets, the timeout can occur
// which causes termination of the connection after
// the given number of seconds without a successful
switch (this->state)
{
case I_CONNECTING:
- this->Instance->Log(DEBUG,"State = I_CONNECTING");
/* Our socket was in write-state, so delete it and re-add it
* in read-state.
*/
if (!this->Instance->SE->AddFd(this))
return false;
}
- if (this->IsIOHooked)
+ if (Instance->Config->GetIOHook(this))
{
try
{
Instance->Config->GetIOHook(this)->OnRawSocketConnect(this->fd);
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+ Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
return this->OnConnected();
Instance->Config->GetIOHook(this)->OnRawSocketAccept(incoming, insp_ntoa(client.sin_addr), this->port);
#endif
}
- catch (ModuleException& modexcept)
+ catch (CoreException& modexcept)
{
- Instance->Log(DEBUG,"Module exception cought: %s",modexcept.GetReason());
+ Instance->Log(DEBUG,"%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
}
}
void InspSocket::SetState(InspSocketState s)
{
- this->Instance->Log(DEBUG,"Socket state change");
this->state = s;
}
}
else
{
- Instance->Log(DEBUG,"State=%d CONNECTED=%d", this->state, I_CONNECTED);
if (this->FlushWriteBuffer())
{
this->Instance->SE->DelFd(this);