LRAUV  revA
SocketException.h
Go to the documentation of this file.
1 #ifndef SOCKETEXCEPTION_H_
2 #define SOCKETEXCEPTION_H_
3 
4 #include <cstring>
5 
7 {
8 public:
9  SocketException( const char* message, int errcode = 0 )
10  : message_( NULL ), errno_( errcode )
11  {
12  int length = strlen( message );
13  if( length > 8191 ) length = 8191;
14  message_ = new char[length + 1];
15  strncpy( message_, message, length );
16  message_[length] = 0;
17  }
18 
19  SocketException( const char* message1, const char* message2, int errcode = 0 )
20  : message_( NULL ), errno_( errcode )
21  {
22  size_t length1 = strlen( message1 );
23  if( length1 > 4095 ) length1 = 4095;
24  size_t length2 = strlen( message2 );
25  if( length2 > 4095 ) length2 = 4095;
26  message_ = new char[length1 + length2 + 1];
27  strncpy( message_, message1, length1 );
28  strncpy( message_ + length1, message2, length2 );
29  message_[length1 + length2] = 0;
30  }
31 
33  {
34  delete[] message_;
35  }
36 
37  const char* what() const throw()
38  {
39  return message_;
40  }
41 
42  int getErrno()
43  {
44  return errno_;
45  }
46 
48  {
49  int length = strlen( old.message_ ) + 1;
50  message_ = new char[ length ];
51  strncpy( message_, old.message_, length );
52  errno_ = old.errno_;
53  }
54 
55 private:
56  char* message_;
57  int errno_;
58 };
59 
60 #endif /*SOCKETEXCEPTION_H_*/
Definition: SocketException.h:6
~SocketException()
Definition: SocketException.h:32
SocketException(const SocketException &old)
Definition: SocketException.h:47
const char * what() const
Definition: SocketException.h:37
int errno_
Definition: SocketException.h:57
int getErrno()
Definition: SocketException.h:42
SocketException(const char *message1, const char *message2, int errcode=0)
Definition: SocketException.h:19
char * message_
Definition: SocketException.h:56
SocketException(const char *message, int errcode=0)
Definition: SocketException.h:9