static int rpc_write_to_socket(struct rpc_context *rpc)
{
- ssize_t count;
+ int64_t count;
if (rpc == NULL) {
return -1;
}
while (rpc->outqueue != NULL) {
- ssize_t total;
+ int64_t total;
total = rpc->outqueue->outdata.size;
int available;
int size;
int pdu_size;
- ssize_t count;
+ int64_t count;
#if defined(WIN32)
if (ioctlsocket(rpc->fd, FIONREAD, &available) != 0) {
rpc_set_error(rpc, "rpc_service: POLLERR, "
"Unknown socket error.");
}
- rpc->connect_cb(rpc, RPC_STATUS_ERROR, rpc->error_string, rpc->connect_data);
+ if (rpc->connect_cb != NULL) {
+ rpc->connect_cb(rpc, RPC_STATUS_ERROR, rpc->error_string, rpc->connect_data);
+ }
return -1;
}
if (revents & POLLHUP) {
rpc_set_error(rpc, "Socket failed with POLLHUP");
- rpc->connect_cb(rpc, RPC_STATUS_ERROR, rpc->error_string, rpc->connect_data);
+ if (rpc->connect_cb != NULL) {
+ rpc->connect_cb(rpc, RPC_STATUS_ERROR, rpc->error_string, rpc->connect_data);
+ }
return -1;
}
rpc_set_error(rpc, "rpc_service: socket error "
"%s(%d) while connecting.",
strerror(err), err);
- rpc->connect_cb(rpc, RPC_STATUS_ERROR,
+ if (rpc->connect_cb != NULL) {
+ rpc->connect_cb(rpc, RPC_STATUS_ERROR,
NULL, rpc->connect_data);
+ }
return -1;
}
rpc->is_connected = 1;
- rpc->connect_cb(rpc, RPC_STATUS_SUCCESS, NULL, rpc->connect_data);
+ if (rpc->connect_cb != NULL) {
+ rpc->connect_cb(rpc, RPC_STATUS_SUCCESS, NULL, rpc->connect_data);
+ }
return 0;
}
* to make the executable able to bind to a system port.
*/
if (1) {
- int port;
+ static int port = 200;
+ int i;
int one = 1;
setsockopt(rpc->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
- for (port = 200; port < 500; port++) {
+ for (i = 0; i < 500; i++) {
struct sockaddr_in sin;
+ if(++port > 700) port = 200;
+
memset(&sin, 0, sizeof(sin));
sin.sin_port = htons(port);
sin.sin_family = AF_INET;
if (connect(rpc->fd, (struct sockaddr *)s, socksize) != 0 && errno != EINPROGRESS)
#endif
{
- rpc_set_error(rpc, "connect() to server failed");
+ rpc_set_error(rpc, "connect() to server failed. %s(%d)", strerror(errno), errno);
return -1;
}
}
rpc->is_connected = 1;
+ rpc->connect_cb = NULL;
}
/* disconnect but do not error all PDUs, just move pdus in-flight back to the outqueue and reconnect */