Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added TCP_DEFER_ACCEPT module for 2.0 #33

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
81 changes: 81 additions & 0 deletions 2.0/m_deferaccept.cpp
@@ -0,0 +1,81 @@
/*
* InspIRCd -- Internet Relay Chat Daemon
*
* Copyright (C) 2013 Daniel Vassdal <shutter@canternet.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
* 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/>.
*/

/* $ModAuthor: Daniel Vassdal */
/* $ModAuthorMail: shutter@canternet.org */
/* $ModDesc: Enable TCP_DEFER_ACCEPT on sockets */
/* $ModDepends: core 2.0 */
/* $ModConfig: <bind defer="0"> */

#include "inspircd.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a copyright header here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are also missing $Mod* comments. Check the other modules to see how they are done.

#include <netinet/tcp.h>

#if !defined TCP_DEFER_ACCEPT && !defined SO_ACCEPTFILTER
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These defines were done via the config script.... how are you doing them now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were only done like that in the initial version. It was later updated to not use a configure test.

#error "This system does not support TCP_DEFER_ACCEPT - you can\'t use this module"
#endif

class ModuleDeferAccept : public Module
{
private:
bool removing;

public:
ModuleDeferAccept() : removing(false)
{
}

void init()
{
OnRehash(NULL);
ServerInstance->Modules->Attach(I_OnRehash, this);
}

void OnRehash(User* user)
{
for (std::vector<ListenSocket*>::const_iterator it = ServerInstance->ports.begin(); it != ServerInstance->ports.end(); ++it)
{
int timeout = 0;
if (!removing)
timeout = (*it)->bind_tag->getInt("defer", 0);

int fd = (*it)->GetFd();
#ifdef TCP_DEFER_ACCEPT
setsockopt(fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &timeout, sizeof(timeout));
#elif defined SO_ACCEPTFILTER
struct accept_filter_arg afa;
memset(&afa, 0, sizeof(afa));
strcpy(afa.af_name, "dataready");
setsockopt(fd, SOL_SOCKET, SO_ACCEPTFILTER, (!timeout ? NULL : &afa), sizeof(afa));
#endif
}
}

~ModuleDeferAccept()
{
removing = true;
OnRehash(NULL);
}

Version GetVersion()
{
return Version("Enable TCP Defer Accept", VF_NONE);
}

};

MODULE_INIT(ModuleDeferAccept)