Files
2024-09-23 12:00:04 -04:00

109 lines
4.7 KiB
C++

#pragma once
/*
* Copyright Onix Solutions Limited [OnixS]. All rights reserved.
*
* This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
* and international copyright treaties.
*
* Access to and use of the software is governed by the terms of the applicable OnixS Software
* Services Agreement (the Agreement) and Customer end user license agreements granting
* a non-assignable, non-transferable and non-exclusive license to use the software
* for it's own data processing purposes under the terms defined in the Agreement.
*
* Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
* of this source code or associated reference material to any other location for further reproduction
* or redistribution, and any amendments to this copyright notice, are expressly prohibited.
*
* Any reproduction or redistribution for sale or hiring of the Software not in accordance with
* the terms of the Agreement is a violation of copyright law.
*/
#include <OnixS/FIXEngine/ABI.h>
#include <OnixS/FIXEngine/Sockets/Definitions.h>
#include <string>
namespace OnixS {
namespace Sockets {
/// Provides client connections for TCP network services.
class ONIXS_FIXENGINE_API TcpClient
{
public:
/// Initializes a new instance of the TcpClient class and connects to the specified port on the specified host.
///
/// @param hostname The DNS name of the remote host to which you intend to connect (or its IP address).
/// @param port The port number of the remote host to which you intend to connect.
/// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until some data is received.
TcpClient(const std::string & hostname, int port, int timeoutInMillisecons = 0);
/// Initializes a new instance of the TcpClient class.
TcpClient();
/// The destructor.
~TcpClient(void);
/// Connects to the specified port on the specified host.
///
/// @param hostname The DNS name of the remote host to which you intend to connect (or its IP address).
/// @param port The port number of the remote host to which you intend to connect.
/// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until some data is received.
void connect(const std::string & hostname, int port, int timeoutInMillisecons = 0);
/// Closes the TCP connection.
void close();
/// Sets a value that disables a delay when send or receive buffers are not full.
///
/// When the setTcpNoDelayOption is false, a TcpClient does not send a packet over the network until it has collected a significant amount of the outgoing data.
/// Because of the amount of overhead in a TCP segment, sending small amounts of data is inefficient.
/// However, situations do exist where you need to send very small amounts of data or expect immediate responses from each packet you send.
/// Your decision should weigh the relative importance of network efficiency versus application requirements.
void noDelay(bool setTcpNoDelayOption);
/// Gets a value that disables a delay when send or receive buffers are not full.
bool noDelay() const;
/// Returns the size of the TCP buffer allocated to the TCP connection for the receiving data.
int receiveBufferSize() const;
/// Sets the size of the TCP buffer allocated to the TCP connection for the receiving data.
void receiveBufferSize(int size);
/// Returns the size of the TCP buffer allocated to the TCP connection for the sending data.
int sendBufferSize() const;
/// Sets the size of the TCP buffer allocated to the TCP connection for the sending data.
void sendBufferSize(int size);
static const Handle InvalidSocketHandle;
/// Returns the socket handle which the TCP connection uses to transmit data.
Handle socketHandle();
/// Sends the given value.
void send(const std::string & value);
/// Sends the given value.
void send(const void * buffer, size_t bufferLength);
/// Receives the data.
///
/// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until some data is received.
const Bytes & receive(int timeoutInMillisecons = 0);
/// Receives exactly the given number of bytes.
///
/// @param numberOfBytesToReceive The number of bytes to received.
/// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until all bytes are received.
const Bytes & receive(size_t numberOfBytesToReceive, int timeoutInMillisecons = 0);
private:
TcpClient(const TcpClient &);
TcpClient & operator = (const TcpClient &);
struct Impl;
Impl * impl_;
};
}
}