mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2025-12-05 23:23:13 +00:00
2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
* librpc/src/rpc/clnt_tcp.c: Partial merger from freebsd (Fix strict-aliasing).
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
|
||||||
|
|
||||||
|
* librpc/src/rpc/clnt_tcp.c: Partial merger from freebsd
|
||||||
|
(Fix strict-aliasing).
|
||||||
|
|
||||||
2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
|
2010-05-26 Ralf Corsépius <ralf.corsepius@rtems.org>
|
||||||
|
|
||||||
* librpc/src/rpc/clnt_raw.c: Partial merger from freebsd
|
* librpc/src/rpc/clnt_raw.c: Partial merger from freebsd
|
||||||
|
|||||||
@@ -90,14 +90,17 @@ static struct clnt_ops tcp_ops = {
|
|||||||
|
|
||||||
struct ct_data {
|
struct ct_data {
|
||||||
int ct_sock;
|
int ct_sock;
|
||||||
bool_t ct_closeit;
|
bool_t ct_closeit; /* close it on destroy */
|
||||||
struct timeval ct_wait;
|
struct timeval ct_wait; /* wait interval in milliseconds */
|
||||||
bool_t ct_waitset; /* wait set by clnt_control? */
|
bool_t ct_waitset; /* wait set by clnt_control? */
|
||||||
struct sockaddr_in ct_addr;
|
struct sockaddr_in ct_addr;
|
||||||
struct rpc_err ct_error;
|
struct rpc_err ct_error;
|
||||||
char ct_mcall[MCALL_MSG_SIZE]; /* marshalled callmsg */
|
union {
|
||||||
|
char ct_mcallc[MCALL_MSG_SIZE]; /* marshalled callmsg */
|
||||||
|
u_int32_t ct_mcalli;
|
||||||
|
} ct_u;
|
||||||
u_int ct_mpos; /* pos after marshal */
|
u_int ct_mpos; /* pos after marshal */
|
||||||
XDR ct_xdrs;
|
XDR ct_xdrs; /* XDR stream */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -124,7 +127,7 @@ clnttcp_create(
|
|||||||
u_int recvsz)
|
u_int recvsz)
|
||||||
{
|
{
|
||||||
CLIENT *h;
|
CLIENT *h;
|
||||||
register struct ct_data *ct = NULL;
|
struct ct_data *ct = NULL; /* client handle */
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
struct rpc_msg call_msg;
|
struct rpc_msg call_msg;
|
||||||
static uintptr_t disrupt;
|
static uintptr_t disrupt;
|
||||||
@@ -139,7 +142,7 @@ clnttcp_create(
|
|||||||
rpc_createerr.cf_error.re_errno = errno;
|
rpc_createerr.cf_error.re_errno = errno;
|
||||||
goto fooy;
|
goto fooy;
|
||||||
}
|
}
|
||||||
ct = (struct ct_data *)mem_alloc(sizeof(*ct));
|
ct = (struct ct_data *)mem_alloc(sizeof (*ct));
|
||||||
if (ct == NULL) {
|
if (ct == NULL) {
|
||||||
(void)fprintf(stderr, "clnttcp_create: out of memory\n");
|
(void)fprintf(stderr, "clnttcp_create: out of memory\n");
|
||||||
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
rpc_createerr.cf_stat = RPC_SYSTEMERROR;
|
||||||
@@ -201,7 +204,7 @@ clnttcp_create(
|
|||||||
/*
|
/*
|
||||||
* pre-serialize the static part of the call msg and stash it away
|
* pre-serialize the static part of the call msg and stash it away
|
||||||
*/
|
*/
|
||||||
xdrmem_create(&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
|
xdrmem_create(&(ct->ct_xdrs), ct->ct_u.ct_mcallc, MCALL_MSG_SIZE,
|
||||||
XDR_ENCODE);
|
XDR_ENCODE);
|
||||||
if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
|
if (! xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
|
||||||
if (ct->ct_closeit) {
|
if (ct->ct_closeit) {
|
||||||
@@ -244,12 +247,12 @@ clnttcp_call(
|
|||||||
caddr_t results_ptr,
|
caddr_t results_ptr,
|
||||||
struct timeval timeout)
|
struct timeval timeout)
|
||||||
{
|
{
|
||||||
register struct ct_data *ct = (struct ct_data *) h->cl_private;
|
struct ct_data *ct = (struct ct_data *) h->cl_private;
|
||||||
register XDR *xdrs = &(ct->ct_xdrs);
|
XDR *xdrs = &(ct->ct_xdrs);
|
||||||
struct rpc_msg reply_msg;
|
struct rpc_msg reply_msg;
|
||||||
u_long x_id;
|
u_int32_t x_id;
|
||||||
u_int32_t *msg_x_id = (u_int32_t *)(ct->ct_mcall); /* yuk */
|
u_int32_t *msg_x_id = &ct->ct_u.ct_mcalli; /* yuk */
|
||||||
register bool_t shipnow;
|
bool_t shipnow;
|
||||||
int refreshes = 2;
|
int refreshes = 2;
|
||||||
|
|
||||||
if (!ct->ct_waitset) {
|
if (!ct->ct_waitset) {
|
||||||
@@ -264,7 +267,7 @@ call_again:
|
|||||||
xdrs->x_op = XDR_ENCODE;
|
xdrs->x_op = XDR_ENCODE;
|
||||||
ct->ct_error.re_status = RPC_SUCCESS;
|
ct->ct_error.re_status = RPC_SUCCESS;
|
||||||
x_id = ntohl(--(*msg_x_id));
|
x_id = ntohl(--(*msg_x_id));
|
||||||
if ((! XDR_PUTBYTES(xdrs, ct->ct_mcall, ct->ct_mpos)) ||
|
if ((! XDR_PUTBYTES(xdrs, ct->ct_u.ct_mcallc, ct->ct_mpos)) ||
|
||||||
(! XDR_PUTLONG(xdrs, (long *)&proc)) ||
|
(! XDR_PUTLONG(xdrs, (long *)&proc)) ||
|
||||||
(! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
|
(! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
|
||||||
(! (*xdr_args)(xdrs, args_ptr))) {
|
(! (*xdr_args)(xdrs, args_ptr))) {
|
||||||
@@ -273,10 +276,12 @@ call_again:
|
|||||||
(void)xdrrec_endofrecord(xdrs, TRUE);
|
(void)xdrrec_endofrecord(xdrs, TRUE);
|
||||||
return (ct->ct_error.re_status);
|
return (ct->ct_error.re_status);
|
||||||
}
|
}
|
||||||
if (! xdrrec_endofrecord(xdrs, shipnow))
|
if (! xdrrec_endofrecord(xdrs, shipnow)) {
|
||||||
return (ct->ct_error.re_status = RPC_CANTSEND);
|
return (ct->ct_error.re_status = RPC_CANTSEND);
|
||||||
if (! shipnow)
|
}
|
||||||
|
if (! shipnow) {
|
||||||
return (RPC_SUCCESS);
|
return (RPC_SUCCESS);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Hack to provide rpc-based message passing
|
* Hack to provide rpc-based message passing
|
||||||
*/
|
*/
|
||||||
@@ -292,7 +297,7 @@ call_again:
|
|||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
reply_msg.acpted_rply.ar_verf = _null_auth;
|
reply_msg.acpted_rply.ar_verf = _null_auth;
|
||||||
reply_msg.acpted_rply.ar_results.where = NULL;
|
reply_msg.acpted_rply.ar_results.where = NULL;
|
||||||
reply_msg.acpted_rply.ar_results.proc = (xdrproc_t) xdr_void;
|
reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
|
||||||
if (! xdrrec_skiprecord(xdrs))
|
if (! xdrrec_skiprecord(xdrs))
|
||||||
return (ct->ct_error.re_status);
|
return (ct->ct_error.re_status);
|
||||||
/* now decode and validate the response header */
|
/* now decode and validate the response header */
|
||||||
@@ -336,9 +341,9 @@ clnttcp_geterr(
|
|||||||
CLIENT *h,
|
CLIENT *h,
|
||||||
struct rpc_err *errp)
|
struct rpc_err *errp)
|
||||||
{
|
{
|
||||||
register struct ct_data *ct =
|
struct ct_data *ct;
|
||||||
(struct ct_data *) h->cl_private;
|
|
||||||
|
|
||||||
|
ct = (struct ct_data *) h->cl_private;
|
||||||
*errp = ct->ct_error;
|
*errp = ct->ct_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -348,9 +353,12 @@ clnttcp_freeres(
|
|||||||
xdrproc_t xdr_res,
|
xdrproc_t xdr_res,
|
||||||
caddr_t res_ptr)
|
caddr_t res_ptr)
|
||||||
{
|
{
|
||||||
register struct ct_data *ct = (struct ct_data *)cl->cl_private;
|
struct ct_data *ct;
|
||||||
register XDR *xdrs = &(ct->ct_xdrs);
|
XDR *xdrs;
|
||||||
|
|
||||||
|
ct = (struct ct_data *)cl->cl_private;
|
||||||
|
xdrs = &(ct->ct_xdrs);
|
||||||
|
|
||||||
xdrs->x_op = XDR_FREE;
|
xdrs->x_op = XDR_FREE;
|
||||||
return ((*xdr_res)(xdrs, res_ptr));
|
return ((*xdr_res)(xdrs, res_ptr));
|
||||||
}
|
}
|
||||||
@@ -367,9 +375,11 @@ clnttcp_control(
|
|||||||
int request,
|
int request,
|
||||||
char *info)
|
char *info)
|
||||||
{
|
{
|
||||||
register struct ct_data *ct = (struct ct_data *)cl->cl_private;
|
struct ct_data *ct;
|
||||||
register struct timeval *tv;
|
struct timeval *tv;
|
||||||
socklen_t len;
|
socklen_t len;
|
||||||
|
|
||||||
|
ct = (struct ct_data *)cl->cl_private;
|
||||||
|
|
||||||
switch (request) {
|
switch (request) {
|
||||||
case CLSET_FD_CLOSE:
|
case CLSET_FD_CLOSE:
|
||||||
@@ -404,18 +414,20 @@ clnttcp_control(
|
|||||||
case CLGET_XID:
|
case CLGET_XID:
|
||||||
/*
|
/*
|
||||||
* use the knowledge that xid is the
|
* use the knowledge that xid is the
|
||||||
* first element in the call structure *.
|
* first element in the call structure
|
||||||
* This will get the xid of the PREVIOUS call
|
* This will get the xid of the PREVIOUS call
|
||||||
*/
|
*/
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
*(u_long *)info = ntohl(*(u_long *)ct->ct_mcall);
|
*(u_int32_t *)info =
|
||||||
|
ntohl(*(u_int32_t *)&ct->ct_u.ct_mcalli);
|
||||||
break;
|
break;
|
||||||
case CLSET_XID:
|
case CLSET_XID:
|
||||||
/* This will set the xid of the NEXT call */
|
/* This will set the xid of the NEXT call */
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
*(u_long *)ct->ct_mcall = htonl(*(u_long *)info - 1);
|
*(u_int32_t *)&ct->ct_u.ct_mcalli =
|
||||||
|
htonl(*((u_int32_t *)info) + 1);
|
||||||
/* decrement by 1 as clnttcp_call() increments once */
|
/* decrement by 1 as clnttcp_call() increments once */
|
||||||
case CLGET_VERS:
|
case CLGET_VERS:
|
||||||
/*
|
/*
|
||||||
@@ -426,38 +438,44 @@ clnttcp_control(
|
|||||||
*/
|
*/
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
*(u_long *)info = ntohl(*(u_long *)(ct->ct_mcall +
|
*(u_int32_t *)info =
|
||||||
|
ntohl(*(u_int32_t *)(ct->ct_u.ct_mcallc +
|
||||||
4 * BYTES_PER_XDR_UNIT));
|
4 * BYTES_PER_XDR_UNIT));
|
||||||
break;
|
break;
|
||||||
case CLSET_VERS:
|
case CLSET_VERS:
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
*(u_long *)(ct->ct_mcall + 4 * BYTES_PER_XDR_UNIT)
|
*(u_int32_t *)(ct->ct_u.ct_mcallc +
|
||||||
= htonl(*(u_long *)info);
|
4 * BYTES_PER_XDR_UNIT) =
|
||||||
|
htonl(*(u_int32_t *)info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLGET_PROG:
|
case CLGET_PROG:
|
||||||
/*
|
/*
|
||||||
* This RELIES on the information that, in the call body,
|
* This RELIES on the information that, in the call body,
|
||||||
* the program number field is the field from the
|
* the program number field is the fourth field from the
|
||||||
* begining of the RPC header. MUST be changed if the
|
* begining of the RPC header. MUST be changed if the
|
||||||
* call_struct is changed
|
* call_struct is changed
|
||||||
*/
|
*/
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
*(u_long *)info = ntohl(*(u_long *)(ct->ct_mcall +
|
*(u_int32_t *)info = ntohl(*(u_int32_t *)(ct->ct_u.ct_mcallc +
|
||||||
3 * BYTES_PER_XDR_UNIT));
|
3 * BYTES_PER_XDR_UNIT));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLSET_PROG:
|
case CLSET_PROG:
|
||||||
if (info == NULL)
|
if (info == NULL)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
*(u_long *)(ct->ct_mcall + 3 * BYTES_PER_XDR_UNIT)
|
*(u_int32_t *)(ct->ct_u.ct_mcallc + 3 * BYTES_PER_XDR_UNIT)
|
||||||
= htonl(*(u_long *)info);
|
= htonl(*(u_int32_t *)info);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLGET_LOCAL_ADDR:
|
case CLGET_LOCAL_ADDR:
|
||||||
len = sizeof(struct sockaddr);
|
len = sizeof(struct sockaddr);
|
||||||
if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0)
|
if (getsockname(ct->ct_sock, (struct sockaddr *)info, &len) <0)
|
||||||
return(FALSE);
|
return(FALSE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CLGET_RETRY_TIMEOUT:
|
case CLGET_RETRY_TIMEOUT:
|
||||||
case CLSET_RETRY_TIMEOUT:
|
case CLSET_RETRY_TIMEOUT:
|
||||||
case CLGET_SVC_ADDR:
|
case CLGET_SVC_ADDR:
|
||||||
@@ -475,15 +493,15 @@ static void
|
|||||||
clnttcp_destroy(
|
clnttcp_destroy(
|
||||||
CLIENT *h)
|
CLIENT *h)
|
||||||
{
|
{
|
||||||
register struct ct_data *ct =
|
struct ct_data *ct =
|
||||||
(struct ct_data *) h->cl_private;
|
(struct ct_data *) h->cl_private;
|
||||||
|
|
||||||
if (ct->ct_closeit) {
|
if (ct->ct_closeit) {
|
||||||
(void)_RPC_close(ct->ct_sock);
|
(void)_RPC_close(ct->ct_sock);
|
||||||
}
|
}
|
||||||
XDR_DESTROY(&(ct->ct_xdrs));
|
XDR_DESTROY(&(ct->ct_xdrs));
|
||||||
mem_free((caddr_t)ct, sizeof(struct ct_data));
|
mem_free(ct, sizeof(struct ct_data));
|
||||||
mem_free((caddr_t)h, sizeof(CLIENT));
|
mem_free(h, sizeof(CLIENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -574,7 +592,7 @@ writetcp(
|
|||||||
int len)
|
int len)
|
||||||
{
|
{
|
||||||
struct ct_data *ct = (struct ct_data *) _ct;
|
struct ct_data *ct = (struct ct_data *) _ct;
|
||||||
register int i, cnt;
|
int i, cnt;
|
||||||
|
|
||||||
for (cnt = len; cnt > 0; cnt -= i, buf += i) {
|
for (cnt = len; cnt > 0; cnt -= i, buf += i) {
|
||||||
if ((i = _RPC_write(ct->ct_sock, buf, cnt)) == -1) {
|
if ((i = _RPC_write(ct->ct_sock, buf, cnt)) == -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user