1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include <sys/resource.h>
22 #include <sys/types.h>
23 #include <sys/socket.h>
24 #include <netinet/in.h>
33 #include "inspircd_io.h"
34 #include "inspircd_util.h"
35 #include "inspstring.h"
36 #include "helperfuncs.h"
38 extern FILE *log_file;
39 extern int boundPortCount;
40 extern int openSockfd[MAXSOCKS];
42 extern bool unlimitcore;
45 InspSocket::InspSocket()
47 this->state = I_DISCONNECTED;
50 InspSocket::InspSocket(std::string host, int port, bool listening, unsigned long maxtime)
56 hostent* hoste = gethostbyname(host.c_str());
58 ip = (char*)host.c_str();
60 struct in_addr* ia = (in_addr*)hoste->h_addr;
64 timeout_end = time(NULL)+maxtime;
66 if ((this->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
68 this->state = I_ERROR;
73 addr.sin_family = AF_INET;
75 addr.sin_port = htons(this->port);
78 flags = fcntl(this->fd, F_GETFL, 0);
79 fcntl(this->fd, F_SETFL, flags | O_NONBLOCK);
81 if(connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1)
83 if (errno != EINPROGRESS)
88 this->state = I_ERROR;
92 this->state = I_CONNECTING;
97 void InspSocket::EngineTrigger()
105 this->OnIncomingConnection();
115 void InspSocket::SetState(InspSocketState s)
120 int InspSocket::OnConnected() { return 0; }
121 int InspSocket::OnError() { return 0; }
122 int InspSocket::OnDisconnect() { return 0; }
123 int InspSocket::OnIncomingConnection() { return 0; }
124 int InspSocket::OnDataReady() { return 0; }
126 InspSocket::~InspSocket()
131 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr)
132 int OpenTCPSocket (void)