sipxportlib  Version 3.3
OsDatagramSocket.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2007 SIPez LLC.
3 // Licensed to SIPfoundry under a Contributor Agreement.
4 //
5 // Copyright (C) 2004-2007 SIPfoundry Inc.
6 // Licensed by SIPfoundry under the LGPL license.
7 //
8 // Copyright (C) 2004-2006 Pingtel Corp. All rights reserved.
9 // Licensed to SIPfoundry under a Contributor Agreement.
10 //
11 // $$
13 
14 
15 #ifndef _OsDatagramSocket_h_
16 #define _OsDatagramSocket_h_
17 
18 // SYSTEM INCLUDES
19 //#include <...>
20 
21 // APPLICATION INCLUDES
22 #include <os/OsSocket.h>
23 
24 // DEFINES
25 // MACROS
26 // EXTERNAL FUNCTIONS
27 // EXTERNAL VARIABLES
28 // CONSTANTS
29 // STRUCTS
30 // TYPEDEFS
31 // FORWARD DECLARATIONS
32 
33 //: Implements UDP version of OsSocket
34 // This class provides the implementation of the UDP datagram-based
35 // socket class which may be instantiated.
36 
37 class OsDatagramSocket : public OsSocket
38 {
39 /* //////////////////////////// PUBLIC //////////////////////////////////// */
40 public:
41 
42 /* ============================ CREATORS ================================== */
43 
46  const char* localHostName = NULL);
47  //:Constructor
48 
49  virtual
51  //:Destructor
52 
53 
54 /* ============================ MANIPULATORS ============================== */
55 
56  virtual UtlBoolean reconnect();
57  //: Sets up the connection again, assuming the connection failed
58 
59  void doConnect(int remotePort, const char* remoteHostName,
60  UtlBoolean simulateConnect = FALSE);
61  // Setup a connection with a remote host on the specified remote port
65 
66  virtual int write(const char* buffer, int bufferLength);
67  //: Blocking write to the socket
68  // Write the characters in the given buffer to the socket.
69  // This method will block until all of the bytes are written.
73 
74  virtual int write(const char* buffer, int bufferLength,
75  const char* ipAddress, int port);
76  //: Blocking write to the socket
77  // Write the characters in the given buffer to the socket.
78  // This method will block until all of the bytes are written.
84 
85  virtual int read(char* buffer, int bufferLength);
86 
87 /* ============================ ACCESSORS ================================= */
89  //: Returns the protocol type of this socket
90 
91 
92  virtual void getRemoteHostIp(struct in_addr* remoteHostAddress,
93  int* remotePort = NULL);
94  //:Return remote host ip address
95  // Returns the ip address for the host on which the socket on the
96  // other end of this socket is bound.
97 
98  virtual UtlBoolean getMappedIp(UtlString* ip, int* port) ;
99  //:Return the external IP address for this socket.
100  // OsStunDatagramSocket will return the NATted address if available,
101 
102 /* ============================ INQUIRY =================================== */
103 
104 /* //////////////////////////// PROTECTED ///////////////////////////////// */
105 protected:
106 
108  //:Bare-bones constructor
109  // Callers will need to call bind & doConnect on their own when this returns
110  // (This allows for children to set socket options before the bind call)
111 
112  int bind(int localHostPortNum = PORT_DEFAULT, const char* localHost = NULL);
113 
114 /* //////////////////////////// PRIVATE /////////////////////////////////// */
115 private:
116  OsDatagramSocket(const OsDatagramSocket& rOsDatagramSocket);
117  //:Disable copy constructor
118 
119  OsDatagramSocket& operator=(const OsDatagramSocket& rhs);
120  //:Disable assignment operator
121 
122  time_t mLastWriteErrorTime;
123  int mNumTotalWriteErrors;
124  int mNumRecentWriteErrors;
125 
126  UtlBoolean mSimulatedConnect;
127  UtlBoolean mToSockaddrValid;
128  struct sockaddr_in* mpToSockaddr;
129 
130  int ctorCommonCode();
131  //:Common code for both constructors.
132 
133  virtual int writeTo(const char* buffer, int bufferLength);
134  //: Blocking write to the socket, with simulated connection
135  // Write the characters in the given buffer to the socket.
136  // This method will block until all of the bytes are written.
140 
141  virtual UtlBoolean getToSockaddr(void);
142 
143 };
144 
145 /* ============================ INLINE METHODS ============================ */
146 
147 #endif // _OsDatagramSocket_h_
Definition: OsSocket.h:79
IpProtocolSocketType
Definition: OsSocket.h:92
virtual void getRemoteHostIp(struct in_addr *remoteHostAddress, int *remotePort=NULL)
Definition: OsDatagramSocket.cpp:533
#define NULL
Definition: UtlDefs.h:29
virtual ~OsDatagramSocket()
Definition: OsDatagramSocket.cpp:150
int bind(int localHostPortNum=PORT_DEFAULT, const char *localHost=NULL)
Definition: OsDatagramSocket.cpp:168
virtual int write(const char *buffer, int bufferLength)
param: remoteHostName - remote host to send datagram(s) in subsequent calls to write (overloaded vers...
Definition: OsDatagramSocket.cpp:328
Definition: UtlString.h:48
Definition: OsDatagramSocket.h:37
virtual UtlBoolean getMappedIp(UtlString *ip, int *port)
Definition: OsDatagramSocket.cpp:577
OsDatagramSocket()
Definition: OsDatagramSocket.cpp:104
int localHostPort
Definition: OsSocket.h:321
virtual UtlBoolean reconnect()
Definition: OsDatagramSocket.cpp:224
virtual int read(char *buffer, int bufferLength)
param: buffer - the bytes to be written to the socket param: bufferLength - the number of bytes conta...
Definition: OsDatagramSocket.cpp:499
int UtlBoolean
Definition: UtlDefs.h:41
virtual OsSocket::IpProtocolSocketType getIpProtocol() const
Definition: OsDatagramSocket.cpp:528
int remoteHostPort
Definition: OsSocket.h:322
#define PORT_DEFAULT
Definition: OsDefs.h:180
void doConnect(int remotePort, const char *remoteHostName, UtlBoolean simulateConnect=FALSE)
Definition: OsDatagramSocket.cpp:230
#define FALSE
Definition: UtlDefs.h:21
UtlString remoteHostName
Definition: OsSocket.h:325
UtlString localHostName
Definition: OsSocket.h:324