52
52
#include <errno.h>
53
53
#include "common.h"
54
54
55
+ // Global stat.
56
+ #ifdef DEBUG
57
+ unsigned long long _st_stat_recvfrom = 0 ;
58
+ unsigned long long _st_stat_recvfrom_eagain = 0 ;
59
+ unsigned long long _st_stat_sendto = 0 ;
60
+ unsigned long long _st_stat_sendto_eagain = 0 ;
61
+ unsigned long long _st_stat_read = 0 ;
62
+ unsigned long long _st_stat_read_eagain = 0 ;
63
+ unsigned long long _st_stat_readv = 0 ;
64
+ unsigned long long _st_stat_readv_eagain = 0 ;
65
+ unsigned long long _st_stat_writev = 0 ;
66
+ unsigned long long _st_stat_writev_eagain = 0 ;
67
+ unsigned long long _st_stat_recvmsg = 0 ;
68
+ unsigned long long _st_stat_recvmsg_eagain = 0 ;
69
+ unsigned long long _st_stat_sendmsg = 0 ;
70
+ unsigned long long _st_stat_sendmsg_eagain = 0 ;
71
+ unsigned long long _st_stat_sendmmsg = 0 ;
72
+ unsigned long long _st_stat_sendmmsg_eagain = 0 ;
73
+ #endif
55
74
56
75
#if EAGAIN != EWOULDBLOCK
57
76
#define _IO_NOT_READY_ERROR ((errno == EAGAIN) || (errno == EWOULDBLOCK))
@@ -437,12 +456,21 @@ int st_connect(_st_netfd_t *fd, const struct sockaddr *addr, int addrlen, st_uti
437
456
ssize_t st_read (_st_netfd_t * fd , void * buf , size_t nbyte , st_utime_t timeout )
438
457
{
439
458
ssize_t n ;
459
+
460
+ #ifdef DEBUG
461
+ ++ _st_stat_read ;
462
+ #endif
440
463
441
464
while ((n = read (fd -> osfd , buf , nbyte )) < 0 ) {
442
465
if (errno == EINTR )
443
466
continue ;
444
467
if (!_IO_NOT_READY_ERROR )
445
468
return -1 ;
469
+
470
+ #ifdef DEBUG
471
+ ++ _st_stat_read_eagain ;
472
+ #endif
473
+
446
474
/* Wait until the socket becomes readable */
447
475
if (st_netfd_poll (fd , POLLIN , timeout ) < 0 )
448
476
return -1 ;
@@ -470,12 +498,21 @@ int st_read_resid(_st_netfd_t *fd, void *buf, size_t *resid, st_utime_t timeout)
470
498
ssize_t st_readv (_st_netfd_t * fd , const struct iovec * iov , int iov_size , st_utime_t timeout )
471
499
{
472
500
ssize_t n ;
501
+
502
+ #ifdef DEBUG
503
+ ++ _st_stat_readv ;
504
+ #endif
473
505
474
506
while ((n = readv (fd -> osfd , iov , iov_size )) < 0 ) {
475
507
if (errno == EINTR )
476
508
continue ;
477
509
if (!_IO_NOT_READY_ERROR )
478
510
return -1 ;
511
+
512
+ #ifdef DEBUG
513
+ ++ _st_stat_readv_eagain ;
514
+ #endif
515
+
479
516
/* Wait until the socket becomes readable */
480
517
if (st_netfd_poll (fd , POLLIN , timeout ) < 0 )
481
518
return -1 ;
@@ -572,6 +609,10 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, st_uti
572
609
nleft = nbyte ;
573
610
tmp_iov = (struct iovec * ) iov ; /* we promise not to modify iov */
574
611
iov_cnt = iov_size ;
612
+
613
+ #ifdef DEBUG
614
+ ++ _st_stat_writev ;
615
+ #endif
575
616
576
617
while (nleft > 0 ) {
577
618
if (iov_cnt == 1 ) {
@@ -616,6 +657,11 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, st_uti
616
657
tmp_iov [iov_cnt ].iov_len = iov [index ].iov_len ;
617
658
}
618
659
}
660
+
661
+ #ifdef DEBUG
662
+ ++ _st_stat_writev_eagain ;
663
+ #endif
664
+
619
665
/* Wait until the socket becomes writable */
620
666
if (st_netfd_poll (fd , POLLOUT , timeout ) < 0 ) {
621
667
rv = -1 ;
@@ -633,6 +679,10 @@ ssize_t st_writev(_st_netfd_t *fd, const struct iovec *iov, int iov_size, st_uti
633
679
int st_writev_resid (_st_netfd_t * fd , struct iovec * * iov , int * iov_size , st_utime_t timeout )
634
680
{
635
681
ssize_t n ;
682
+
683
+ #ifdef DEBUG
684
+ ++ _st_stat_writev ;
685
+ #endif
636
686
637
687
while (* iov_size > 0 ) {
638
688
if (* iov_size == 1 )
@@ -659,6 +709,11 @@ int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, st_utime
659
709
(* iov )-> iov_base = (char * ) (* iov )-> iov_base + n ;
660
710
(* iov )-> iov_len -= n ;
661
711
}
712
+
713
+ #ifdef DEBUG
714
+ ++ _st_stat_writev_eagain ;
715
+ #endif
716
+
662
717
/* Wait until the socket becomes writable */
663
718
if (st_netfd_poll (fd , POLLOUT , timeout ) < 0 )
664
719
return -1 ;
@@ -674,12 +729,21 @@ int st_writev_resid(_st_netfd_t *fd, struct iovec **iov, int *iov_size, st_utime
674
729
int st_recvfrom (_st_netfd_t * fd , void * buf , int len , struct sockaddr * from , int * fromlen , st_utime_t timeout )
675
730
{
676
731
int n ;
677
-
732
+
733
+ #ifdef DEBUG
734
+ ++ _st_stat_recvfrom ;
735
+ #endif
736
+
678
737
while ((n = recvfrom (fd -> osfd , buf , len , 0 , from , (socklen_t * )fromlen )) < 0 ) {
679
738
if (errno == EINTR )
680
739
continue ;
681
740
if (!_IO_NOT_READY_ERROR )
682
741
return -1 ;
742
+
743
+ #ifdef DEBUG
744
+ ++ _st_stat_recvfrom_eagain ;
745
+ #endif
746
+
683
747
/* Wait until the socket becomes readable */
684
748
if (st_netfd_poll (fd , POLLIN , timeout ) < 0 )
685
749
return -1 ;
@@ -692,12 +756,21 @@ int st_recvfrom(_st_netfd_t *fd, void *buf, int len, struct sockaddr *from, int
692
756
int st_sendto (_st_netfd_t * fd , const void * msg , int len , const struct sockaddr * to , int tolen , st_utime_t timeout )
693
757
{
694
758
int n ;
759
+
760
+ #ifdef DEBUG
761
+ ++ _st_stat_sendto ;
762
+ #endif
695
763
696
764
while ((n = sendto (fd -> osfd , msg , len , 0 , to , tolen )) < 0 ) {
697
765
if (errno == EINTR )
698
766
continue ;
699
767
if (!_IO_NOT_READY_ERROR )
700
768
return -1 ;
769
+
770
+ #ifdef DEBUG
771
+ ++ _st_stat_sendto_eagain ;
772
+ #endif
773
+
701
774
/* Wait until the socket becomes writable */
702
775
if (st_netfd_poll (fd , POLLOUT , timeout ) < 0 )
703
776
return -1 ;
@@ -710,12 +783,21 @@ int st_sendto(_st_netfd_t *fd, const void *msg, int len, const struct sockaddr *
710
783
int st_recvmsg (_st_netfd_t * fd , struct msghdr * msg , int flags , st_utime_t timeout )
711
784
{
712
785
int n ;
786
+
787
+ #ifdef DEBUG
788
+ ++ _st_stat_recvmsg ;
789
+ #endif
713
790
714
791
while ((n = recvmsg (fd -> osfd , msg , flags )) < 0 ) {
715
792
if (errno == EINTR )
716
793
continue ;
717
794
if (!_IO_NOT_READY_ERROR )
718
795
return -1 ;
796
+
797
+ #ifdef DEBUG
798
+ ++ _st_stat_recvmsg_eagain ;
799
+ #endif
800
+
719
801
/* Wait until the socket becomes readable */
720
802
if (st_netfd_poll (fd , POLLIN , timeout ) < 0 )
721
803
return -1 ;
@@ -728,12 +810,21 @@ int st_recvmsg(_st_netfd_t *fd, struct msghdr *msg, int flags, st_utime_t timeou
728
810
int st_sendmsg (_st_netfd_t * fd , const struct msghdr * msg , int flags , st_utime_t timeout )
729
811
{
730
812
int n ;
813
+
814
+ #ifdef DEBUG
815
+ ++ _st_stat_sendmsg ;
816
+ #endif
731
817
732
818
while ((n = sendmsg (fd -> osfd , msg , flags )) < 0 ) {
733
819
if (errno == EINTR )
734
820
continue ;
735
821
if (!_IO_NOT_READY_ERROR )
736
822
return -1 ;
823
+
824
+ #ifdef DEBUG
825
+ ++ _st_stat_sendmsg_eagain ;
826
+ #endif
827
+
737
828
/* Wait until the socket becomes writable */
738
829
if (st_netfd_poll (fd , POLLOUT , timeout ) < 0 )
739
830
return -1 ;
@@ -749,6 +840,10 @@ int st_sendmmsg(st_netfd_t fd, struct st_mmsghdr *msgvec, unsigned int vlen, int
749
840
int left ;
750
841
struct mmsghdr * p ;
751
842
843
+ #ifdef DEBUG
844
+ ++ _st_stat_sendmmsg ;
845
+ #endif
846
+
752
847
left = (int )vlen ;
753
848
while (left > 0 ) {
754
849
p = (struct mmsghdr * )msgvec + (vlen - left );
@@ -758,6 +853,11 @@ int st_sendmmsg(st_netfd_t fd, struct st_mmsghdr *msgvec, unsigned int vlen, int
758
853
continue ;
759
854
if (!_IO_NOT_READY_ERROR )
760
855
break ;
856
+
857
+ #ifdef DEBUG
858
+ ++ _st_stat_sendmmsg_eagain ;
859
+ #endif
860
+
761
861
/* Wait until the socket becomes writable */
762
862
if (st_netfd_poll (fd , POLLOUT , timeout ) < 0 )
763
863
break ;
0 commit comments