2009-07-29 12:07:54 +02:00
|
|
|
/*
|
2010-01-05 08:29:35 +01:00
|
|
|
Copyright (c) 2007-2010 iMatix Corporation
|
2009-07-29 12:07:54 +02:00
|
|
|
|
|
|
|
This file is part of 0MQ.
|
|
|
|
|
|
|
|
0MQ is free software; you can redistribute it and/or modify it under
|
2010-10-30 15:08:28 +02:00
|
|
|
the terms of the GNU Lesser General Public License as published by
|
2009-07-29 12:07:54 +02:00
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
0MQ 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
|
2010-10-30 15:08:28 +02:00
|
|
|
GNU Lesser General Public License for more details.
|
2009-07-29 12:07:54 +02:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-07-29 12:07:54 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-08-03 11:30:13 +02:00
|
|
|
#ifndef __ZMQ_TCP_CONNECTER_HPP_INCLUDED__
|
|
|
|
#define __ZMQ_TCP_CONNECTER_HPP_INCLUDED__
|
2009-07-29 12:07:54 +02:00
|
|
|
|
2010-02-09 19:23:15 +01:00
|
|
|
#include "platform.hpp"
|
2009-07-29 12:07:54 +02:00
|
|
|
#include "fd.hpp"
|
2010-02-09 19:23:15 +01:00
|
|
|
|
|
|
|
#ifdef ZMQ_HAVE_WINDOWS
|
|
|
|
#include "windows.hpp"
|
|
|
|
#else
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#endif
|
2009-07-29 12:07:54 +02:00
|
|
|
|
2009-08-03 11:30:13 +02:00
|
|
|
namespace zmq
|
2009-07-29 12:07:54 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
// The class encapsulating simple TCP listening socket.
|
|
|
|
|
|
|
|
class tcp_connecter_t
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
tcp_connecter_t ();
|
|
|
|
~tcp_connecter_t ();
|
|
|
|
|
2010-01-15 14:11:39 +01:00
|
|
|
// Set address to connect to.
|
|
|
|
int set_address (const char *protocol, const char *addr_);
|
2009-08-09 16:12:09 +02:00
|
|
|
|
2009-07-29 12:07:54 +02:00
|
|
|
// Open TCP connecting socket. Address is in
|
|
|
|
// <hostname>:<port-number> format. Returns -1 in case of error,
|
|
|
|
// 0 if connect was successfull immediately and 1 if async connect
|
|
|
|
// was launched.
|
2009-08-09 16:12:09 +02:00
|
|
|
int open ();
|
2009-07-29 12:07:54 +02:00
|
|
|
|
|
|
|
// Close the connecting socket.
|
|
|
|
int close ();
|
|
|
|
|
|
|
|
// Get the file descriptor to poll on to get notified about
|
|
|
|
// connection success.
|
|
|
|
fd_t get_fd ();
|
|
|
|
|
|
|
|
// Get the file descriptor of newly created connection. Returns
|
|
|
|
// retired_fd if the connection was unsuccessfull.
|
|
|
|
fd_t connect ();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2009-08-09 16:12:09 +02:00
|
|
|
// Address to connect to.
|
2010-01-22 13:13:52 +01:00
|
|
|
sockaddr_storage addr;
|
2010-01-23 08:19:30 +01:00
|
|
|
socklen_t addr_len;
|
2009-08-09 16:12:09 +02:00
|
|
|
|
2009-07-29 12:07:54 +02:00
|
|
|
// Underlying socket.
|
|
|
|
fd_t s;
|
|
|
|
|
|
|
|
tcp_connecter_t (const tcp_connecter_t&);
|
|
|
|
void operator = (const tcp_connecter_t&);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|