Remote Call Framework 3.2
TimedBsdSockets.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2020, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 3.2
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_TIMEDBSDSOCKETS_HPP
20 #define INCLUDE_RCF_TIMEDBSDSOCKETS_HPP
21 
22 #include <vector>
23 
24 #include <RCF/ClientProgress.hpp>
25 #include <RCF/Export.hpp>
26 #include <RCF/BsdSockets.hpp> // GetErrorString()
27 #include <RCF/RcfFwd.hpp>
28 
29 namespace RCF {
30 
31  class ByteBuffer;
32 
33  class I_PollingFunctor
34  {
35  public:
36  virtual ~I_PollingFunctor() {}
37  virtual int operator()(int, int &, bool) = 0;
38  };
39 
40  class PollingFunctor : public I_PollingFunctor
41  {
42  public:
43  PollingFunctor(
44  ClientProgressPtr clientProgressPtr,
45  RemoteCallPhase activity,
46  unsigned int endTimeMs);
47 
48  int operator()(int fd, int &err, bool bRead);
49 
50  private:
51  ClientProgressPtr mClientProgressPtr;
52  RemoteCallPhase mActivity;
53  unsigned int mEndTimeMs;
54  };
55 
56  // return -2 for timeout, -1 for error, 0 for ready
57  RCF_EXPORT int pollSocket(
58  unsigned int endTimeMs,
59  int fd,
60  int &err,
61  bool bRead);
62 
63  // return -2 for timeout, -1 for error, 0 for ready
64  RCF_EXPORT int pollSocketWithProgress(
65  ClientProgressPtr ClientProgressPtr,
66  RemoteCallPhase activity,
67  unsigned int endTimeMs,
68  int fd,
69  int &err,
70  bool bRead);
71 
72  //******************************************************
73  // nonblocking socket routines
74 
75  // returns -2 for timeout, -1 for error, otherwise 0
76  RCF_EXPORT int timedConnect(
77  I_PollingFunctor &pollingFunctor,
78  int &err,
79  int fd,
80  const sockaddr *addr,
81  int addrLen);
82 
83  // returns -2 for timeout, -1 for error, otherwise number of bytes sent (> 0)
84  RCF_EXPORT int timedSend(
85  I_PollingFunctor &pollingFunctor,
86  int &err,
87  int fd,
88  const std::vector<ByteBuffer> &byteBuffers,
89  std::size_t maxSendSize,
90  int flags);
91 
92  class BsdClientTransport;
93 
94  // returns -2 for timeout, -1 for error, 0 for peer closure, otherwise size of packet read
95  RCF_EXPORT int timedRecv(
96  BsdClientTransport &clientTransport,
97  I_PollingFunctor &pollingFunctor,
98  int &err,
99  int fd,
100  const ByteBuffer &byteBuffer,
101  std::size_t bytesRequested,
102  int flags);
103 
104  RCF_EXPORT bool isFdConnected(int fd);
105 
106  RCF_EXPORT std::pair<std::string, std::vector<std::string> > getLocalIps();
107 
108 } // namespace RCF
109 
110 
111 #endif // ! INCLUDE_RCF_TIMEDBSDSOCKETS_HPP
Definition: AmiIoHandler.hpp:24
RemoteCallPhase
Describes which activity a remote call is currently in.
Definition: Enums.hpp:183