uint32_t hisport;
+ int failed=0;
+
XBT_IN("");
gras_trp_socket_new(1, &res);
sock_errstr(tmp_errno));
}
- if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &i, s)
- || setsockopt(sd, _gras_tcp_proto_number(), TCP_NODELAY, (char *) &i,
- s))
+ if (_gras_tcp_proto_number()!=-1)
+ if (setsockopt(sd, _gras_tcp_proto_number(), TCP_NODELAY, (char *) &i,s))
+ failed=1;
+
+ if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *) &i, s))
+ failed=1;
+
+ if (failed)
THROWF(system_error, 0,
"setsockopt failed, cannot condition the socket: %s",
sock_errstr(tmp_errno));
if (!sock)
return; /* close only once */
- if (((gras_trp_tcp_sock_data_t)sock->data)->peer_name)
- free(((gras_trp_tcp_sock_data_t)sock->data)->peer_name);
+ free(((gras_trp_tcp_sock_data_t)sock->data)->peer_name);
free(sock->data);
XBT_VERB("close tcp connection %d", sock->sd);
data->in_buf.size - data->in_buf.pos,
data->in_buf.size, data->in_buf.pos);
}
- if (data->in_buf.data)
- free(data->in_buf.data);
+ free(data->in_buf.data);
if (data->out_buf.size != data->out_buf.pos) {
XBT_DEBUG("Flush the socket before closing (in=%d,out=%d)",
data->in_buf.size, data->out_buf.size);
gras_trp_bufiov_flush(sock);
}
- if (data->out_buf.data)
- free(data->out_buf.data);
+ free(data->out_buf.data);
#ifdef HAVE_READV
if (data->in_buf_v) {
/****************************/
/*
- * Returns the tcp protocol number from the network protocol data base.
+ * Returns the tcp protocol number from the network protocol data base, or -1 if not found
*
* getprotobyname() is not thread safe. We need to lock it.
*/
if (returnValue == 0) {
fetchedEntry = getprotobyname("tcp");
- xbt_assert0(fetchedEntry, "getprotobyname(tcp) gave NULL");
- returnValue = fetchedEntry->p_proto;
+ if (fetchedEntry == NULL) {
+ XBT_VERB("getprotobyname(tcp) gave NULL");
+ returnValue = -1;
+ } else {
+ returnValue = fetchedEntry->p_proto;
+ }
}
return returnValue;