OnixS C++ FIX Engine  4.12.0
API Documentation
TcpClient.h
Go to the documentation of this file.
1 #pragma once
2 /*
3 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
4 *
5 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
6 * and international copyright treaties.
7 *
8 * Access to and use of the software is governed by the terms of the applicable OnixS Software
9 * Services Agreement (the Agreement) and Customer end user license agreements granting
10 * a non-assignable, non-transferable and non-exclusive license to use the software
11 * for it's own data processing purposes under the terms defined in the Agreement.
12 *
13 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
14 * of this source code or associated reference material to any other location for further reproduction
15 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
16 *
17 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
18 * the terms of the Agreement is a violation of copyright law.
19 */
20 
21 #include <OnixS/FIXEngine/ABI.h>
23 
24 #include <string>
25 
26 namespace OnixS {
27 namespace Sockets {
28 /// Provides client connections for TCP network services.
30 {
31 public:
32  /// Initializes a new instance of the TcpClient class and connects to the specified port on the specified host.
33  ///
34  /// @param hostname The DNS name of the remote host to which you intend to connect (or its IP address).
35  /// @param port The port number of the remote host to which you intend to connect.
36  /// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until some data is received.
37  TcpClient(const std::string & hostname, int port, int timeoutInMillisecons = 0);
38 
39  /// Initializes a new instance of the TcpClient class.
40  TcpClient();
41 
42  /// The destructor.
43  ~TcpClient(void);
44 
45  /// Connects to the specified port on the specified host.
46  ///
47  /// @param hostname The DNS name of the remote host to which you intend to connect (or its IP address).
48  /// @param port The port number of the remote host to which you intend to connect.
49  /// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until some data is received.
50  void connect(const std::string & hostname, int port, int timeoutInMillisecons = 0);
51 
52  /// Closes the TCP connection.
53  void close();
54 
55  /// Sets a value that disables a delay when send or receive buffers are not full.
56  ///
57  /// 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.
58  /// Because of the amount of overhead in a TCP segment, sending small amounts of data is inefficient.
59  /// However, situations do exist where you need to send very small amounts of data or expect immediate responses from each packet you send.
60  /// Your decision should weigh the relative importance of network efficiency versus application requirements.
61  void noDelay(bool setTcpNoDelayOption);
62 
63  /// Gets a value that disables a delay when send or receive buffers are not full.
64  bool noDelay() const;
65 
66  /// Returns the size of the TCP buffer allocated to the TCP connection for the receiving data.
67  int receiveBufferSize() const;
68 
69  /// Sets the size of the TCP buffer allocated to the TCP connection for the receiving data.
70  void receiveBufferSize(int size);
71 
72  /// Returns the size of the TCP buffer allocated to the TCP connection for the sending data.
73  int sendBufferSize() const;
74 
75  /// Sets the size of the TCP buffer allocated to the TCP connection for the sending data.
76  void sendBufferSize(int size);
77 
79 
80  /// Returns the socket handle which the TCP connection uses to transmit data.
81  Handle socketHandle();
82 
83  /// Sends the given value.
84  void send(const std::string & value);
85 
86  /// Sends the given value.
87  void send(const void * buffer, size_t bufferLength);
88 
89  /// Receives the data.
90  ///
91  /// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until some data is received.
92  const Bytes & receive(int timeoutInMillisecons = 0);
93 
94  /// Receives exactly the given number of bytes.
95  ///
96  /// @param numberOfBytesToReceive The number of bytes to received.
97  /// @param timeoutInMillisecons The timeout value in milliseconds. If 0 then the method blocks until all bytes are received.
98  const Bytes & receive(size_t numberOfBytesToReceive, int timeoutInMillisecons = 0);
99 
100 private:
101  TcpClient(const TcpClient &);
102  TcpClient & operator = (const TcpClient &);
103 
104  struct Impl;
105  Impl * impl_;
106 };
107 }
108 }
virtual void close(bool keepSequenceNumbers, bool doBackup)=0
Closes the storage.
int Handle
Type alias for socket handle.
Definition: Definitions.h:50
std::vector< Byte > Bytes
Sequence of bytes.
Definition: Definitions.h:43
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
static const Handle InvalidSocketHandle
Definition: TcpClient.h:78
Provides client connections for TCP network services.
Definition: TcpClient.h:29