34 #include <sys/select.h> 35 #include <sys/types.h> 38 #include <sys/ioctl.h> 42 #include <boost/format.hpp> 51 std::cerr <<
"Failed to create server socket... I quit." << std::endl;
59 bzero((
char*) &server_address,
sizeof(server_address));
60 server_address.sun_family = AF_UNIX;
61 strncpy(server_address.sun_path, path.c_str(),
sizeof(server_address.sun_path));
62 unlink(server_address.sun_path);
63 int len = strlen(server_address.sun_path) +
sizeof(server_address.sun_family);
68 if (bind(
server_socket, (
struct sockaddr *) &server_address, len) < 0) {
69 std::cerr <<
"Couldn't bind Unix domain socket at path " << path <<
" I quit." << std::endl;
76 std::cerr <<
"Couldn't listen on Unix socket " << path <<
" got " << errno <<
" I quit." << std::endl;
89 std::cerr << boost::format(
"Failed to create client socket on [%s]... I quit.\n")
94 server_address.sun_family = AF_UNIX;
95 strncpy(server_address.sun_path, path.c_str(),
sizeof(server_address.sun_path));
96 int len = strlen(server_address.sun_path) +
sizeof(server_address.sun_family);
99 for(retry_count = 0; retry_count < startup_timeout_count; retry_count++) {
100 stat = connect(
conn_socket, (
struct sockaddr *) &server_address, len);
109 std::cerr <<
"Client couldn't connect to UNIX socket [" << path <<
"]. I quit." << std::endl;
121 if(
ready)
return true;
142 char * bptr = (
char*) ptr;
146 stat = write(fd, bptr, left);
148 if((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
168 if(stat < 0)
return stat;
180 stat = read(
conn_socket, &rsize,
sizeof(
unsigned int));
182 if((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
187 perror(
"Oops -- socket get -- ");
193 char * bptr = (
char*) ptr;
197 if((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
201 perror(
"Ooops -- read buffer continued");
213 unsigned int left = rsize - size;
216 ls = read(
conn_socket, dmy, (left > 100) ? 100 : left);
218 if((errno == EWOULDBLOCK) || (errno == EAGAIN)) {
222 perror(
"Ooops -- read buffer continued");
std::string mailbox_pathname
int loopWrite(int fd, const void *ptr, unsigned int nbytes)
ClientSocket(const std::string &path, int startup_timeout_count=1)
ServerSocket(const std::string &path)
struct sockaddr_un server_address client_address
int put(const void *ptr, unsigned int size)
int get(void *ptr, unsigned int size)