/*
* InspIRCd -- Internet Relay Chat Daemon
*
- * Copyright (C) 2014 Adam <Adam@anope.org>
- * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- * Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
+ * Copyright (C) 2013-2015 Attila Molnar <attilamolnar@hush.com>
+ * Copyright (C) 2013, 2017, 2019 Sadie Powell <sadie@witchery.services>
+ * Copyright (C) 2012 Robby <robby@chatbelgie.be>
+ * Copyright (C) 2012 ChrisTX <xpipe@hotmail.de>
+ * Copyright (C) 2011, 2014 Adam <Adam@anope.org>
+ * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
+ * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ * Copyright (C) 2006-2008 Craig Edwards <brain@inspircd.org>
*
* 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
void SocketEngine::Init()
{
- MAX_DESCRIPTORS = FD_SETSIZE;
+#ifdef _WIN32
+ // Set up winsock.
+ WSADATA wsadata;
+ WSAStartup(MAKEWORD(2,2), &wsadata);
+#endif
+
+ MaxSetSize = FD_SETSIZE;
FD_ZERO(&ReadSet);
FD_ZERO(&WriteSet);
bool SocketEngine::AddFd(EventHandler* eh, int event_mask)
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+
+ if (fd < 0)
+ return false;
+
+ if (static_cast<size_t>(fd) >= GetMaxFds())
return false;
if (!SocketEngine::AddFdRef(eh))
{
int fd = eh->GetFd();
- if ((fd < 0) || (fd > GetMaxFds() - 1))
+ if (fd < 0)
+ return;
+
+ if (static_cast<size_t>(fd) >= GetMaxFds())
return;
SocketEngine::DelFdRef(eh);
if (has_read)
{
- stats.ReadEvents++;
ev->SetEventMask(ev->GetEventMask() & ~FD_READ_WILL_BLOCK);
ev->OnEventHandlerRead();
if (ev != GetRef(i))
if (has_write)
{
- stats.WriteEvents++;
int newmask = (ev->GetEventMask() & ~(FD_WRITE_WILL_BLOCK | FD_WANT_SINGLE_WRITE));
SocketEngine::OnSetEvent(ev, ev->GetEventMask(), newmask);
ev->SetEventMask(newmask);