@@ -25,6 +25,7 @@ import (
25
25
durpb "github.com/golang/protobuf/ptypes/duration"
26
26
channelzpb "google.golang.org/grpc/channelz/grpc_channelz_v1"
27
27
"google.golang.org/grpc/internal/channelz"
28
+ "google.golang.org/grpc/internal/testutils"
28
29
)
29
30
30
31
func convertToPtypesDuration (sec int64 , usec int64 ) * durpb.Duration {
@@ -34,41 +35,32 @@ func convertToPtypesDuration(sec int64, usec int64) *durpb.Duration {
34
35
func sockoptToProto (skopts * channelz.SocketOptionData ) []* channelzpb.SocketOption {
35
36
var opts []* channelzpb.SocketOption
36
37
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
+ }),
40
44
})
41
- if err == nil {
42
- opts = append (opts , & channelzpb.SocketOption {
43
- Name : "SO_LINGER" ,
44
- Additional : additional ,
45
- })
46
- }
47
45
}
48
46
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
+ }),
51
52
})
52
- if err == nil {
53
- opts = append (opts , & channelzpb.SocketOption {
54
- Name : "SO_RCVTIMEO" ,
55
- Additional : additional ,
56
- })
57
- }
58
53
}
59
54
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
+ }),
62
60
})
63
- if err == nil {
64
- opts = append (opts , & channelzpb.SocketOption {
65
- Name : "SO_SNDTIMEO" ,
66
- Additional : additional ,
67
- })
68
- }
69
61
}
70
62
if skopts .TCPInfo != nil {
71
- additional , err := ptypes .MarshalAny (& channelzpb.SocketOptionTcpInfo {
63
+ additional := testutils .MarshalAny (& channelzpb.SocketOptionTcpInfo {
72
64
TcpiState : uint32 (skopts .TCPInfo .State ),
73
65
TcpiCaState : uint32 (skopts .TCPInfo .Ca_state ),
74
66
TcpiRetransmits : uint32 (skopts .TCPInfo .Retransmits ),
@@ -99,12 +91,10 @@ func sockoptToProto(skopts *channelz.SocketOptionData) []*channelzpb.SocketOptio
99
91
TcpiAdvmss : skopts .TCPInfo .Advmss ,
100
92
TcpiReordering : skopts .TCPInfo .Reordering ,
101
93
})
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
+ })
108
98
}
109
99
return opts
110
100
}
0 commit comments