@@ -67,13 +67,13 @@ struct usrsockdev_s
67
67
struct
68
68
{
69
69
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
73
73
* 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
77
77
* threads */
78
78
} req ;
79
79
@@ -245,30 +245,6 @@ static ssize_t iovec_put(FAR struct iovec *iov, int iovcnt, size_t pos,
245
245
return iovec_do ((FAR void * )src , srclen , iov , iovcnt , pos , false);
246
246
}
247
247
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
-
272
248
/****************************************************************************
273
249
* Name: usrsockdev_semtake() and usrsockdev_semgive()
274
250
*
@@ -714,7 +690,7 @@ static ssize_t usrsockdev_handle_req_response(FAR struct usrsockdev_s *dev,
714
690
size_t len )
715
691
{
716
692
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 ;
718
694
unsigned int hdrlen ;
719
695
ssize_t ret ;
720
696
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,
734
710
break ;
735
711
736
712
default :
737
- nwarn ("unknown message type: %d, flags: %d, xid: %02x , "
713
+ nwarn ("unknown message type: %d, flags: %d, xid: %" PRIu64 " , "
738
714
"result: %" PRId32 "\n" ,
739
715
hdr -> head .msgid , hdr -> head .flags , hdr -> xid , hdr -> result );
740
716
return - EINVAL ;
@@ -751,27 +727,20 @@ static ssize_t usrsockdev_handle_req_response(FAR struct usrsockdev_s *dev,
751
727
752
728
/* Get corresponding usrsock connection for this transfer */
753
729
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 );
763
732
if (!conn )
764
733
{
765
734
/* No connection waiting for this message. */
766
735
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 );
769
738
770
739
ret = - EINVAL ;
771
740
goto unlock_out ;
772
741
}
773
742
774
- if (dev -> req .ack_xid == hdr -> xid && dev -> req .iov )
743
+ if (dev -> req .ackxid == hdr -> xid && dev -> req .iov )
775
744
{
776
745
/* Signal that request was received and read by daemon and
777
746
* acknowledgment response was received.
@@ -969,8 +938,8 @@ static int usrsockdev_open(FAR struct file *filep)
969
938
static int usrsockdev_close (FAR struct file * filep )
970
939
{
971
940
FAR struct inode * inode = filep -> f_inode ;
941
+ FAR struct usrsock_conn_s * conn = NULL ;
972
942
FAR struct usrsockdev_s * dev ;
973
- FAR struct usrsock_conn_s * conn ;
974
943
int ret ;
975
944
976
945
DEBUGASSERT (inode );
@@ -987,24 +956,17 @@ static int usrsockdev_close(FAR struct file *filep)
987
956
988
957
ninfo ("closing /dev/usrsock\n" );
989
958
959
+ net_lock ();
960
+
990
961
/* Set active usrsock sockets to aborted state. */
991
962
992
- conn = usrsock_nextconn (NULL );
993
- while (conn )
963
+ while ((conn = usrsock_nextconn (conn )) != NULL )
994
964
{
995
- net_lock ();
996
-
997
965
conn -> resp .inprogress = false;
998
966
conn -> resp .xid = 0 ;
999
967
usrsock_event (conn , USRSOCK_EVENT_ABORT );
1000
-
1001
- net_unlock ();
1002
-
1003
- conn = usrsock_nextconn (conn );
1004
968
}
1005
969
1006
- net_lock ();
1007
-
1008
970
/* Decrement the references to the driver. */
1009
971
1010
972
dev -> ocount -- ;
@@ -1192,7 +1154,7 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
1192
1154
1193
1155
/* Get exchange id. */
1194
1156
1195
- req_head -> xid = usrsockdev_get_xid ( conn ) ;
1157
+ req_head -> xid = ( uintptr_t ) conn ;
1196
1158
1197
1159
/* Prepare connection for response. */
1198
1160
@@ -1208,7 +1170,7 @@ int usrsockdev_do_request(FAR struct usrsock_conn_s *conn,
1208
1170
if (usrsockdev_is_opened (dev ))
1209
1171
{
1210
1172
DEBUGASSERT (dev -> req .iov == NULL );
1211
- dev -> req .ack_xid = req_head -> xid ;
1173
+ dev -> req .ackxid = req_head -> xid ;
1212
1174
dev -> req .iov = iov ;
1213
1175
dev -> req .pos = 0 ;
1214
1176
dev -> req .iovcnt = iovcnt ;
0 commit comments