diff options
| author | mvgr <none@none> | 2005-08-04 14:21:54 -0700 |
|---|---|---|
| committer | mvgr <none@none> | 2005-08-04 14:21:54 -0700 |
| commit | 56b04ea668163bd43a8a0560b2c2df82e3330823 (patch) | |
| tree | f4321f20313eea7dbf5232a15549d1740ea2bb7b | |
| parent | 5c2306d7b8d7035ac2e8be1611ab19d49adf9a34 (diff) | |
| download | illumos-joyent-56b04ea668163bd43a8a0560b2c2df82e3330823.tar.gz | |
6298924 stale data on virtual channels should be cleandup when channel end-user points dies
| -rw-r--r-- | usr/src/lib/libpcp/common/libpcp.c | 40 | ||||
| -rw-r--r-- | usr/src/lib/libpcp/common/libpcp.h | 4 |
2 files changed, 28 insertions, 16 deletions
diff --git a/usr/src/lib/libpcp/common/libpcp.c b/usr/src/lib/libpcp/common/libpcp.c index 9e7ce7efee..9d32387ff0 100644 --- a/usr/src/lib/libpcp/common/libpcp.c +++ b/usr/src/lib/libpcp/common/libpcp.c @@ -44,6 +44,7 @@ #include <inttypes.h> #include <umem.h> #include <strings.h> +#include <time.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/glvc.h> @@ -68,7 +69,7 @@ static int pcp_send_req_msg_hdr(pcp_req_msg_hdr_t *req_hdr); static int pcp_recv_resp_msg_hdr(pcp_resp_msg_hdr_t *resp_hdr); static int pcp_io_op(void *buf, int byte_cnt, int io_op); -static int pcp_get_xid(void); +static uint32_t pcp_get_xid(void); static int pcp_get_prop(int channel_fd, int prop, unsigned int *val); static int pcp_read(uint8_t *buf, int buf_len); static int pcp_write(uint8_t *buf, int buf_len); @@ -185,11 +186,6 @@ pcp_init(char *channel_name) } /* - * Initialize Message Transaction ID. - */ - msg_xid = PCPL_INIT_XID; - - /* * Get the Channel MTU size */ @@ -992,15 +988,35 @@ pcp_recv_resp_msg_hdr(pcp_resp_msg_hdr_t *resp_hdr) * Every request and response message are matched * for same xid. */ -static int pcp_get_xid(void) + +static uint32_t +pcp_get_xid(void) { uint32_t ret; + struct timeval tv; + static boolean_t xid_initialized = B_FALSE; + + if (xid_initialized == B_FALSE) { + xid_initialized = B_TRUE; + /* + * starting xid is initialized to a different value everytime + * user application is restarted so that user apps will not + * receive previous session's packets. + * + * Note: The algorithm for generating initial xid is partially + * taken from Solaris rpc code. + */ + (void) gettimeofday(&tv, NULL); + msg_xid = (uint32_t)((tv.tv_sec << 20) | + (tv.tv_usec >> 10)); + } + + ret = msg_xid++; + + /* zero xid is not allowed */ + if (ret == 0) + ret = msg_xid++; - ret = msg_xid; - if (msg_xid == PCPL_MAX_XID) - msg_xid = PCPL_MIN_XID; - else - ++msg_xid; return (ret); } diff --git a/usr/src/lib/libpcp/common/libpcp.h b/usr/src/lib/libpcp/common/libpcp.h index f45520cf33..3366ef1b50 100644 --- a/usr/src/lib/libpcp/common/libpcp.h +++ b/usr/src/lib/libpcp/common/libpcp.h @@ -33,10 +33,6 @@ extern "C" { #endif -#define PCPL_MIN_XID (0xFF) -#define PCPL_MAX_XID (0xFFFFFFFF) -#define PCPL_INIT_XID (0xFF) - #define PCPL_MAX_TRY_CNT 5 #define PCP_CLEANUP_TIMEOUT 3 |
