-/* +------------------------------------+
- * | Inspire Internet Relay Chat Daemon |
- * +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
*
- * InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2007-2009 Robin Burchell <robin+git@viroteck.net>
+ * Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ * Copyright (C) 2006-2007 Craig Edwards <craigedwards@brainbox.cc>
+ * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
*
- * This program is free but copyrighted software; see
- * the file COPYING for details.
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
*
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+
#include "inspircd.h"
#include "socket.h"
#include "inspstring.h"
#ifndef DISABLE_WRITEV
#include <sys/uio.h>
+#endif
+
#ifndef IOV_MAX
#define IOV_MAX 1024
#endif
-#endif
BufferedSocket::BufferedSocket()
{
this->state = I_CONNECTING;
- if (!ServerInstance->SE->AddFd(this, FD_WANT_NO_READ | FD_WANT_SINGLE_WRITE))
+ if (!ServerInstance->SE->AddFd(this, FD_WANT_NO_READ | FD_WANT_SINGLE_WRITE | FD_WRITE_WILL_BLOCK))
return I_ERR_NOMOREFDS;
this->Timeout = new SocketTimeout(this->GetFd(), this, timeout, ServerInstance->Time());
{
if (this->fd > -1)
{
+ // final chance, dump as much of the sendq as we can
+ DoWrite();
if (IOHook)
{
try
else
{
char* ReadBuffer = ServerInstance->GetReadBuffer();
- int n = recv(fd, ReadBuffer, ServerInstance->Config->NetBufferSize, 0);
+ int n = ServerInstance->SE->Recv(this, ReadBuffer, ServerInstance->Config->NetBufferSize, 0);
if (n == ServerInstance->Config->NetBufferSize)
{
ServerInstance->SE->ChangeEventMask(this, FD_WANT_FAST_READ | FD_ADD_TRIAL_READ);
}
}
+/* Don't try to prepare huge blobs of data to send to a blocked socket */
+static const int MYIOV_MAX = IOV_MAX < 128 ? IOV_MAX : 128;
+
void StreamSocket::DoWrite()
{
if (sendq.empty())
{
// Prepare a writev() call to write all buffers efficiently
int bufcount = sendq.size();
-
- // cap the number of buffers at IOV_MAX
- if (bufcount > IOV_MAX)
+
+ // cap the number of buffers at MYIOV_MAX
+ if (bufcount > MYIOV_MAX)
{
- bufcount = IOV_MAX;
+ bufcount = MYIOV_MAX;
}
int rv_max = 0;
// connection.
this->sock->OnTimeout();
this->sock->OnError(I_ERR_TIMEOUT);
-
- /* NOTE: We must set this AFTER DelFd, as we added
- * this socket whilst writeable. This means that we
- * must DELETE the socket whilst writeable too!
- */
this->sock->state = I_ERROR;
ServerInstance->GlobalCulls.AddItem(sock);