RCFProto
 All Classes Functions Typedefs
TimedBsdSockets.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, 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: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_TIMEDBSDSOCKETS_HPP
20 #define INCLUDE_RCF_TIMEDBSDSOCKETS_HPP
21 
22 #include <RCF/ByteBuffer.hpp>
23 #include <RCF/ClientProgress.hpp>
24 #include <RCF/Export.hpp>
25 #include <RCF/util/Platform/OS/BsdSockets.hpp> // GetErrorString()
26 
27 namespace RCF {
28 
29  class I_PollingFunctor
30  {
31  public:
32  virtual ~I_PollingFunctor() {}
33  virtual int operator()(int, int &, bool) = 0;
34  };
35 
36  class PollingFunctor : public I_PollingFunctor
37  {
38  public:
39  PollingFunctor(
40  ClientProgressPtr clientProgressPtr,
41  ClientProgress::Activity activity,
42  unsigned int endTimeMs);
43 
44  int operator()(int fd, int &err, bool bRead);
45 
46  private:
47  ClientProgressPtr mClientProgressPtr;
48  ClientProgress::Activity mActivity;
49  unsigned int mEndTimeMs;
50  };
51 
52  // return -2 for timeout, -1 for error, 0 for ready
53  RCF_EXPORT int pollSocket(
54  unsigned int endTimeMs,
55  int fd,
56  int &err,
57  bool bRead);
58 
59  // return -2 for timeout, -1 for error, 0 for ready
60  RCF_EXPORT int pollSocketWithProgress(
61  ClientProgressPtr ClientProgressPtr,
62  ClientProgress::Activity activity,
63  unsigned int endTimeMs,
64  int fd,
65  int &err,
66  bool bRead);
67 
68  //******************************************************
69  // nonblocking socket routines
70 
71  // returns -2 for timeout, -1 for error, otherwise 0
72  RCF_EXPORT int timedConnect(
73  I_PollingFunctor &pollingFunctor,
74  int &err,
75  int fd,
76  const sockaddr *addr,
77  int addrLen);
78 
79  // returns -2 for timeout, -1 for error, otherwise number of bytes sent (> 0)
80  RCF_EXPORT int timedSend(
81  I_PollingFunctor &pollingFunctor,
82  int &err,
83  int fd,
84  const std::vector<ByteBuffer> &byteBuffers,
85  std::size_t maxSendSize,
86  int flags);
87 
88  class BsdClientTransport;
89 
90  // returns -2 for timeout, -1 for error, 0 for peer closure, otherwise size of packet read
91  RCF_EXPORT int timedRecv(
92  BsdClientTransport &clientTransport,
93  I_PollingFunctor &pollingFunctor,
94  int &err,
95  int fd,
96  const ByteBuffer &byteBuffer,
97  std::size_t bytesRequested,
98  int flags);
99 
100  RCF_EXPORT bool isFdConnected(int fd);
101 
102  std::pair<std::string, std::vector<std::string> > getLocalIps();
103 
104 } // namespace RCF
105 
106 
107 #endif // ! INCLUDE_RCF_TIMEDBSDSOCKETS_HPP