Commit Graph
47 Commits
Author SHA1 Message Date
Florent Le Coz 8c34576ea0 Move some members of TCPSocketHandler into the SocketHandler class 2014-07-03 03:31:50 +02:00
Florent Le Coz 04d999168a Add a level of inheritance above SocketHandler
SocketHandler has been renamed to TCPSocketHandler
SocketHandler is now a simple interface with a few methods, used only by
Poller.

This way we can inherite from the new SocketHandler class, to handle other
types of sockets, and still make them manageable by the poller without any
change in the Poller class.
2014-07-02 03:01:09 +02:00
Florent Le Coz 7b785cf552 Delete the timeout event using the correct socket number, instead of -1
Was causing the event to not be removed in case of connection failure, which
lead to a dangling timed event named “timeout-1”, which was called later, by
some other SocketHandler for which even the socket creation failed (so, its
socket is -1), with a pointer to the previous SocketHandler which has
disappeared for a long time: segmentation fault etc.
2014-06-22 23:56:51 +02:00
Florent Le Coz 77fe8b89a3 Make the Botan rng, credential_manager etc be static
This actually makes the session_manager be useful, and saves a few octets of
memory for the other ones
2014-06-19 01:04:40 +02:00
Florent Le Coz 8b30e312bb Add a TimedEvent to cancel the connection to a server after 5 seconds 2014-06-08 15:13:08 +02:00
Florent Le Coz 23f32ba39e Implement TLS support using Botan
For now, it tries two TLS ports and then connects to the non-tls port.  In
the future we would like the user to be able to configure that.

fix #2435
2014-06-08 05:07:54 +02:00
Florent Le Coz be6265544a Make the destructor of the SocketHandler class protected non-virtual 2014-06-05 02:24:03 +02:00
Florent Le Coz e033b6a3ae On connection in-progress, save the whole addrinfo struct, not just ai_addr 2014-05-28 02:03:36 +02:00
Florent Le Coz 7b31bea75b Only close/unmanage the socket if we are connected/connecting
Since the socket is now only created and managed whenever the connection is
being established, we only close the socket and if it was created (we use -1
to denote the fact that is not yet created, or has been closed) and we only
unmanage the socket if it is effectively managed.

fix #2529
2014-05-27 23:47:45 +02:00
Florent Le Coz 23e8e32f84 Support IPv6 connections
fix #2522
2014-05-27 01:06:45 +02:00
Florent Le Coz 5507adbe94 SocketHandlers own the poller and add themself into it only when the socket is created
We want to call socket() with the parameters provided by getaddrinfo, so we
can’t addd the fd into the poller immediately. We need to wait the
connection attempt, and then the SocketHandler can call add_socket_handler
itself, if the connection succeeds, or is in progress.
2014-05-27 01:01:44 +02:00
Florent Le Coz 6b0ffb5fc2 If both write and read events are available on a socket, only do the read
Because the read handler may discover that the connection has been closed,
and then remove the socket from the poller. It that case it is no longer
valid to try to call the write handler (which may try to reconnect, but
since that socket is no longer managed, this is not OK).
2014-05-26 22:27:43 +02:00
Florent Le Coz 28d244631d Add missing std::string_literals 2014-04-29 23:51:32 +02:00
Florent Le Coz f6e6b8905b Use C++14 string_literals 2014-04-29 21:50:13 +02:00
Florent Le Coz 58a2c00d44 Call on_connection_failed() when the connection fails to be established 2014-04-15 06:47:38 +02:00
Florent Le Coz f7b75d7eb4 Remove a useless debug log line 2014-04-15 06:42:00 +02:00
Florent Le Coz ffc820e234 Reconnected immediately to the XMPP whenever it closes the connection 2014-03-24 20:31:02 +01:00
Florent Le Coz e196d2f1f4 Do not send data if we are connected, send it only once we actually are 2014-03-24 18:37:31 +01:00
Florent Le Coz 930696e48a Remove useless cast 2014-03-10 00:12:42 +01:00
Florent Le Coz 601159e8e2 Fix a bus error by not going above an array boundary 2014-03-03 21:02:55 +01:00
Florent Le Coz 86d4347af8 Avoid unnecessary copies by recv()ing data directly into the expat buffer 2014-02-28 01:14:38 +01:00
Florent Le Coz df774d45a9 Use scatter/gather io with sendmsg to avoid concataning strings all the time 2014-02-27 23:43:05 +01:00
Florent Le Coz e2b9e80244 Fix a wrong comment 2014-02-26 01:15:44 +01:00
Florent Le Coz 541af5236e Consider that the connect() succeded if errno EISCONN
Apparently on some systems, subsquent connect() calls may fail with EISCONN
error, to indicate that the connection succeded in the background, instead
of returning 0.
2014-02-22 23:36:03 +01:00
Florent Le Coz 730cc6e1bd Save the addrinfo values for reuse on subsequent connect() call 2014-02-22 23:35:14 +01:00
Florent Le Coz 99aba5667d Connection to servers does not block the process anymore 2014-02-22 21:42:24 +01:00
Florent Le Coz e390b79a12 Do not receive SIGPIPE when send() is called on a closed socket
The error is handled using the return value
2014-02-20 00:00:05 +01:00
Florent Le Coz 16be9af3fc Send unavailable presence to all muc when the IRC server closes the connection 2014-02-19 23:59:43 +01:00
Florent Le Coz d46e7ee8c9 Enable TCP keepalive on sockets 2014-02-08 08:14:24 +01:00
Florent Le Coz eb2a2e75c2 Add missing logger include 2014-02-08 08:14:08 +01:00
Florent Le Coz da85617428 Use strerror and log_error instead of perrror 2014-02-08 07:59:02 +01:00
Florent Le Coz c8b41d5e35 Be verbose about IRC server connection failures, and handle them properly 2014-02-08 07:52:22 +01:00
Florent Le Coz d1c6d64546 Add missing stdexcept includes 2014-01-13 20:19:10 +01:00
Florent Le Coz 7701c90763 Add missing errno.h includes 2014-01-04 02:48:08 +01:00
Florent Le Coz baf03a7e20 Do not throw an exception when recv returns and error, just close the socket 2014-01-04 01:59:36 +01:00
Florent Le Coz aa53276859 Keep a "connected" state in the SocketHandler class 2014-01-04 01:59:35 +01:00
Florent Le Coz 3afb63a650 Shutdown cleanly on SIGINT 2014-01-04 01:59:14 +01:00
Florent Le Coz 983477084c connect() returns a boolean 2013-12-24 14:03:40 +01:00
Florent Le Coz 2ecb637f0c Read a variable number of bytes, 4096 by default 2013-12-23 17:07:43 +01:00
Florent Le Coz a4c845ab6c Use the logger everywhere 2013-12-03 19:15:37 +01:00
Florent Le Coz b72908548d Let the user choose the poller to use through cmake POLLER option
Use ccmake, or cmake -i, or cmake -DPOLLER=EPOLL, for example
2013-11-21 00:35:15 +01:00
Florent Le Coz b569240a55 Use epoll 2013-11-21 00:35:15 +01:00
Florent Le Coz 6a43d350be Add include for perror 2013-11-10 03:08:45 +01:00
Florent Le Coz d834d6ed06 Exit the poller when it handles no connection at all 2013-11-03 17:55:23 +01:00
Florent Le Coz 358b53faef Move the basic socket implementation into the SocketHandler class
(that is, the read/write/connect/etc)
Because this code is actually common for both the IrcClient and
XmppComponent class. These two classes have to implement some higher level
callbacks (parsing the data provided in the buffers, doing stuff when the
connection is done) instead of doing the read/write/connect low level
things.
2013-11-02 23:39:00 +01:00
Florent Le Coz 4027ef8c00 Basic IRC message parsing/sending 2013-11-02 16:04:10 +01:00
Florent Le Coz 7869ef2ace First step of the connection skeleton
Basic connect, socket creating, polling, recving, etc.
2013-11-02 03:19:24 +01:00