File tree 1 file changed +19
-10
lines changed
utils/socket-utils/src/main/java17/datadog/common/socket
1 file changed +19
-10
lines changed Original file line number Diff line number Diff line change 15
15
import java .nio .channels .Selector ;
16
16
import java .nio .channels .SocketChannel ;
17
17
import java .nio .file .Path ;
18
+ import java .util .Iterator ;
18
19
19
20
/**
20
21
* Subtype UNIX socket for a higher-fidelity impersonation of TCP sockets. This is named "tunneling"
@@ -128,19 +129,27 @@ public InputStream getInputStream() throws IOException {
128
129
ByteBuffer buffer = ByteBuffer .allocate (256 );
129
130
130
131
try {
131
- if (selector .select (timeout ) == 0 ) {
132
- System .out .println ("Timeout (" + timeout + "ms) while waiting for data." );
133
- }
134
- for (SelectionKey key : selector .selectedKeys ()) {
135
- if (key .isReadable ()) {
136
- int r = unixSocketChannel .read (buffer );
137
- if (r == -1 ) {
138
- unixSocketChannel .close ();
139
- System .out .println ("Not accepting client messages anymore." );
132
+ while (true ) {
133
+ if (selector .select (timeout ) == 0 ) {
134
+ System .out .println ("Timeout (" + timeout + "ms) while waiting for data." );
135
+ break ;
136
+ }
137
+ Iterator <SelectionKey > keyIterator = selector .selectedKeys ().iterator ();
138
+ while (keyIterator .hasNext ()) {
139
+ SelectionKey key = keyIterator .next ();
140
+ keyIterator .remove ();
141
+ if (key .isReadable ()) {
142
+ int r = unixSocketChannel .read (buffer );
143
+ if (r == -1 ) {
144
+ unixSocketChannel .close ();
145
+ System .out .println ("Not accepting client messages anymore." );
146
+ return InputStream .nullInputStream ();
147
+ }
140
148
}
141
149
}
150
+ buffer .flip ();
151
+ break ;
142
152
}
143
- buffer .flip ();
144
153
} finally {
145
154
selector .close ();
146
155
}
You can’t perform that action at this time.
0 commit comments