Skip to content

Commit cbe9352

Browse files
anchaoxiaoxiang781216
authored andcommitted
net/usrsock: remove the connections limit
replace xid type to uint64_t to avoid connections limit Signed-off-by: chao.an <[email protected]>
1 parent c6bd160 commit cbe9352

File tree

4 files changed

+26
-83
lines changed

4 files changed

+26
-83
lines changed

include/nuttx/net/usrsock.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ enum usrsock_message_types_e
9696

9797
begin_packed_struct struct usrsock_request_common_s
9898
{
99-
int8_t reqid;
100-
uint8_t xid;
99+
uint64_t xid;
100+
int8_t reqid;
101+
int8_t reserved;
101102
} end_packed_struct;
102103

103104
begin_packed_struct struct usrsock_request_socket_s
@@ -227,9 +228,9 @@ begin_packed_struct struct usrsock_message_req_ack_s
227228
{
228229
struct usrsock_message_common_s head;
229230

230-
uint8_t xid;
231-
uint8_t reserved;
232-
int32_t result;
231+
int16_t reserved;
232+
int32_t result;
233+
uint64_t xid;
233234
} end_packed_struct;
234235

235236
/* Request acknowledgment/completion message */

net/usrsock/usrsock.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ struct usrsock_conn_s
106106
struct
107107
{
108108
sem_t sem; /* Request semaphore (only one outstanding request) */
109-
uint8_t xid; /* Expected message exchange id */
109+
uint64_t xid; /* Expected message exchange id */
110110
bool inprogress; /* Request was received but daemon is still processing */
111111
uint16_t valuelen; /* Length of value from daemon */
112112
uint16_t valuelen_nontrunc; /* Actual length of value at daemon */
@@ -209,12 +209,6 @@ void usrsock_free(FAR struct usrsock_conn_s *conn);
209209

210210
FAR struct usrsock_conn_s *usrsock_nextconn(FAR struct usrsock_conn_s *conn);
211211

212-
/****************************************************************************
213-
* Name: usrsock_connidx()
214-
****************************************************************************/
215-
216-
int usrsock_connidx(FAR struct usrsock_conn_s *conn);
217-
218212
/****************************************************************************
219213
* Name: usrsock_active()
220214
*

net/usrsock/usrsock_conn.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,20 +180,6 @@ FAR struct usrsock_conn_s *usrsock_nextconn(FAR struct usrsock_conn_s *conn)
180180
}
181181
}
182182

183-
/****************************************************************************
184-
* Name: usrsock_connidx()
185-
****************************************************************************/
186-
187-
int usrsock_connidx(FAR struct usrsock_conn_s *conn)
188-
{
189-
int idx = conn - g_usrsock_connections;
190-
191-
DEBUGASSERT(idx >= 0);
192-
DEBUGASSERT(idx < ARRAY_SIZE(g_usrsock_connections));
193-
194-
return idx;
195-
}
196-
197183
/****************************************************************************
198184
* Name: usrsock_active()
199185
*

net/usrsock/usrsock_dev.c

Lines changed: 19 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ struct usrsockdev_s
6767
struct
6868
{
6969
FAR const struct iovec *iov; /* Pending request buffers */
70-
int iovcnt; /* Number of request buffers */
71-
size_t pos; /* Reader position on request buffer */
72-
sem_t sem; /* Request semaphore (only one outstanding
70+
int iovcnt; /* Number of request buffers */
71+
size_t pos; /* Reader position on request buffer */
72+
sem_t sem; /* Request semaphore (only one outstanding
7373
* request) */
74-
sem_t acksem; /* Request acknowledgment notification */
75-
uint8_t ack_xid; /* Exchange id for which waiting ack */
76-
uint16_t nbusy; /* Number of requests blocked from different
74+
sem_t acksem; /* Request acknowledgment notification */
75+
uint64_t ackxid; /* Exchange id for which waiting ack */
76+
uint16_t nbusy; /* Number of requests blocked from different
7777
* threads */
7878
} req;
7979

@@ -245,30 +245,6 @@ static ssize_t iovec_put(FAR struct iovec *iov, int iovcnt, size_t pos,
245245
return iovec_do((FAR void *)src, srclen, iov, iovcnt, pos, false);
246246
}
247247

248-
/****************************************************************************
249-
* Name: usrsockdev_get_xid()
250-
****************************************************************************/
251-
252-
static uint8_t usrsockdev_get_xid(FAR struct usrsock_conn_s *conn)
253-
{
254-
int conn_idx;
255-
256-
#if CONFIG_NET_USRSOCK_CONNS > 254
257-
# error "CONFIG_NET_USRSOCK_CONNS too large (over 254)"
258-
#endif
259-
260-
/* Each connection can one only one request/response pending. So map
261-
* connection structure index to xid value.
262-
*/
263-
264-
conn_idx = usrsock_connidx(conn);
265-
266-
DEBUGASSERT(1 <= conn_idx + 1);
267-
DEBUGASSERT(conn_idx + 1 <= UINT8_MAX);
268-
269-
return conn_idx + 1;
270-
}
271-
272248
/****************************************************************************
273249
* Name: usrsockdev_semtake() and usrsockdev_semgive()
274250
*
@@ -714,7 +690,7 @@ static ssize_t usrsockdev_handle_req_response(FAR struct usrsockdev_s *dev,
714690
size_t len)
715691
{
716692
FAR const struct usrsock_message_req_ack_s *hdr = buffer;
717-
FAR struct usrsock_conn_s *conn;
693+
FAR struct usrsock_conn_s *conn = NULL;
718694
unsigned int hdrlen;
719695
ssize_t ret;
720696
ssize_t (*handle_response)(FAR struct usrsockdev_s *dev,
@@ -734,7 +710,7 @@ static ssize_t usrsockdev_handle_req_response(FAR struct usrsockdev_s *dev,
734710
break;
735711

736712
default:
737-
nwarn("unknown message type: %d, flags: %d, xid: %02x, "
713+
nwarn("unknown message type: %d, flags: %d, xid: %" PRIu64 ", "
738714
"result: %" PRId32 "\n",
739715
hdr->head.msgid, hdr->head.flags, hdr->xid, hdr->result);
740716
return -EINVAL;
@@ -751,27 +727,20 @@ static ssize_t usrsockdev_handle_req_response(FAR struct usrsockdev_s *dev,
751727

752728
/* Get corresponding usrsock connection for this transfer */
753729

754-
conn = usrsock_nextconn(NULL);
755-
while (conn)
756-
{
757-
if (conn->resp.xid == hdr->xid)
758-
break;
759-
760-
conn = usrsock_nextconn(conn);
761-
}
762-
730+
while ((conn = usrsock_nextconn(conn)) != NULL &&
731+
conn->resp.xid != hdr->xid);
763732
if (!conn)
764733
{
765734
/* No connection waiting for this message. */
766735

767-
nwarn("Could find connection waiting for response with xid=%d\n",
768-
hdr->xid);
736+
nwarn("Could find connection waiting for response"
737+
"with xid=%" PRIu64 "\n", hdr->xid);
769738

770739
ret = -EINVAL;
771740
goto unlock_out;
772741
}
773742

774-
if (dev->req.ack_xid == hdr->xid && dev->req.iov)
743+
if (dev->req.ackxid == hdr->xid && dev->req.iov)
775744
{
776745
/* Signal that request was received and read by daemon and
777746
* acknowledgment response was received.
@@ -969,8 +938,8 @@ static int usrsockdev_open(FAR struct file *filep)
969938
static int usrsockdev_close(FAR struct file *filep)
970939
{
971940
FAR struct inode *inode = filep->f_inode;
941+
FAR struct usrsock_conn_s *conn = NULL;
972942
FAR struct usrsockdev_s *dev;
973-
FAR struct usrsock_conn_s *conn;
974943
int ret;
975944

976945
DEBUGASSERT(inode);
@@ -987,24 +956,17 @@ static int usrsockdev_close(FAR struct file *filep)
987956

988957
ninfo("closing /dev/usrsock\n");
989958

959+
net_lock();
960+
990961
/* Set active usrsock sockets to aborted state. */
991962

992-
conn = usrsock_nextconn(NULL);
993-
while (conn)
963+
while ((conn = usrsock_nextconn(conn)) != NULL)
994964
{
995-
net_lock();
996-
997965
conn->resp.inprogress = false;
998966
conn->resp.xid = 0;
999967
usrsock_event(conn, USRSOCK_EVENT_ABORT);
1000-
1001-
net_unlock();
1002-
1003-
conn = usrsock_nextconn(conn);
1004968
}
1005969

1006-
net_lock();
1007-
1008970
/* Decrement the references to the driver. */
1009971

1010972
dev->ocount--;
@@ -1192,7 +1154,7 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
11921154

11931155
/* Get exchange id. */
11941156

1195-
req_head->xid = usrsockdev_get_xid(conn);
1157+
req_head->xid = (uintptr_t)conn;
11961158

11971159
/* Prepare connection for response. */
11981160

@@ -1208,7 +1170,7 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
12081170
if (usrsockdev_is_opened(dev))
12091171
{
12101172
DEBUGASSERT(dev->req.iov == NULL);
1211-
dev->req.ack_xid = req_head->xid;
1173+
dev->req.ackxid = req_head->xid;
12121174
dev->req.iov = iov;
12131175
dev->req.pos = 0;
12141176
dev->req.iovcnt = iovcnt;

0 commit comments

Comments
 (0)