8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
13 #include <barry/barry.h>
21 ///////////////////////////////////////////////////////////////////////////////
22 // JDWP::Error exception class
24 static std::string
GetErrorString(int errcode
, const std::string
&str
)
26 std::ostringstream oss
;
30 oss
<< std::setbase(10) << errcode
<< ", ";
33 // oss << strerror(-libusb_errno) << "): "
40 Error::Error(const std::string
&str
)
41 : Barry::Error(GetErrorString(0, str
))
47 Error::Error(int errcode
, const std::string
&str
)
48 : Barry::Error(GetErrorString(errcode
, str
))
55 ///////////////////////////////////////////////////////////////////////////////
56 // JDWP::JDWP communication class
68 bool JDWP::Read(int socket
, Barry::Data
&data
, int timeout
)
75 ret
= read(socket
, (char*) data
.GetBuffer(), data
.GetBufSize());
79 if (ret
!= -EINTR
&& ret
!= -EAGAIN
) {
81 if( ret
== -ETIMEDOUT
)
82 throw Timeout(ret
, "Timeout in read");
84 throw Error(ret
, "Error in read");
88 data
.ReleaseBuffer(ret
);
89 } while( ret
== -EINTR
);
95 bool JDWP::Write(int socket
, const Barry::Data
&data
, int timeout
)
100 ret
= write(socket
, (char*) data
.GetData(), data
.GetSize());
102 if( ret
< 0 && ret
!= -EINTR
&& ret
!= -EAGAIN
) {
104 if( ret
== -ETIMEDOUT
)
105 throw Timeout(ret
, "Timeout in write (1)");
107 throw Error(ret
, "Error in write (1)");
109 } while( ret
== -EINTR
|| ret
== -EAGAIN
);
115 bool JDWP::Write(int socket
, const void *data
, size_t size
, int timeout
)
120 ret
= write(socket
, (char*) data
, size
);
122 if( ret
< 0 && ret
!= -EINTR
&& ret
!= -EAGAIN
) {
124 if( ret
== -ETIMEDOUT
)
125 throw Timeout(ret
, "Timeout in write (2)");
127 throw Error(ret
, "Error in write (2)");
129 } while( ret
== -EINTR
|| ret
== -EAGAIN
);