@@ -25,6 +25,7 @@ import (
2525 durpb "github.com/golang/protobuf/ptypes/duration"
2626 channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
2727 "google.golang.org/grpc/internal/channelz"
28+ "google.golang.org/grpc/internal/testutils"
2829)
2930
3031func convertToPtypesDuration (sec int64 , usec int64 ) * durpb.Duration {
@@ -34,41 +35,32 @@ func convertToPtypesDuration(sec int64, usec int64) *durpb.Duration {
3435func sockoptToProto (skopts * channelz.SocketOptionData ) []* channelzpb.SocketOption {
3536 var opts []* channelzpb.SocketOption
3637 if skopts .Linger != nil {
37- additional , err := ptypes .MarshalAny (& channelzpb.SocketOptionLinger {
38- Active : skopts .Linger .Onoff != 0 ,
39- Duration : convertToPtypesDuration (int64 (skopts .Linger .Linger ), 0 ),
38+ opts = append (opts , & channelzpb.SocketOption {
39+ Name : "SO_LINGER" ,
40+ Additional : testutils .MarshalAny (& channelzpb.SocketOptionLinger {
41+ Active : skopts .Linger .Onoff != 0 ,
42+ Duration : convertToPtypesDuration (int64 (skopts .Linger .Linger ), 0 ),
43+ }),
4044 })
41- if err == nil {
42- opts = append (opts , & channelzpb.SocketOption {
43- Name : "SO_LINGER" ,
44- Additional : additional ,
45- })
46- }
4745 }
4846 if skopts .RecvTimeout != nil {
49- additional , err := ptypes .MarshalAny (& channelzpb.SocketOptionTimeout {
50- Duration : convertToPtypesDuration (int64 (skopts .RecvTimeout .Sec ), int64 (skopts .RecvTimeout .Usec )),
47+ opts = append (opts , & channelzpb.SocketOption {
48+ Name : "SO_RCVTIMEO" ,
49+ Additional : testutils .MarshalAny (& channelzpb.SocketOptionTimeout {
50+ Duration : convertToPtypesDuration (int64 (skopts .RecvTimeout .Sec ), int64 (skopts .RecvTimeout .Usec )),
51+ }),
5152 })
52- if err == nil {
53- opts = append (opts , & channelzpb.SocketOption {
54- Name : "SO_RCVTIMEO" ,
55- Additional : additional ,
56- })
57- }
5853 }
5954 if skopts .SendTimeout != nil {
60- additional , err := ptypes .MarshalAny (& channelzpb.SocketOptionTimeout {
61- Duration : convertToPtypesDuration (int64 (skopts .SendTimeout .Sec ), int64 (skopts .SendTimeout .Usec )),
55+ opts = append (opts , & channelzpb.SocketOption {
56+ Name : "SO_SNDTIMEO" ,
57+ Additional : testutils .MarshalAny (& channelzpb.SocketOptionTimeout {
58+ Duration : convertToPtypesDuration (int64 (skopts .SendTimeout .Sec ), int64 (skopts .SendTimeout .Usec )),
59+ }),
6260 })
63- if err == nil {
64- opts = append (opts , & channelzpb.SocketOption {
65- Name : "SO_SNDTIMEO" ,
66- Additional : additional ,
67- })
68- }
6961 }
7062 if skopts .TCPInfo != nil {
71- additional , err := ptypes .MarshalAny (& channelzpb.SocketOptionTcpInfo {
63+ additional := testutils .MarshalAny (& channelzpb.SocketOptionTcpInfo {
7264 TcpiState : uint32 (skopts .TCPInfo .State ),
7365 TcpiCaState : uint32 (skopts .TCPInfo .Ca_state ),
7466 TcpiRetransmits : uint32 (skopts .TCPInfo .Retransmits ),
@@ -99,12 +91,10 @@ func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOptio
9991 TcpiAdvmss : skopts .TCPInfo .Advmss ,
10092 TcpiReordering : skopts .TCPInfo .Reordering ,
10193 })
102- if err == nil {
103- opts = append (opts , & channelzpb.SocketOption {
104- Name : "TCP_INFO" ,
105- Additional : additional ,
106- })
107- }
94+ opts = append (opts , & channelzpb.SocketOption {
95+ Name : "TCP_INFO" ,
96+ Additional : additional ,
97+ })
10898 }
10999 return opts
110100}
0 commit comments