Skip to content

Commit f931770

Browse files
authored
UNIX Domain Socket support (helidon-io#10894)
* add support for UNIX domain sockets to webserver and webclient * use SocketChannel in server listener (required for the above) * add support for socket channels when accepting connections to webserver * bind-address was left in configuration from older versions of Helidon, and it now has a new meaning - fix all usages * fix Optional.of() to ofNullable() for local certificate and principal.
1 parent 8b791a3 commit f931770

64 files changed

Lines changed: 1997 additions & 359 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

common/buffers/src/main/java/io/helidon/common/buffers/BufferData.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@ static BufferData create(String stringValue) {
214214
*/
215215
int readFrom(InputStream in);
216216

217+
/**
218+
* Read bytes from the provided buffer.
219+
*
220+
* @param buf byte buffer with data
221+
* @return number of bytes read, -1 if the buffer is finished
222+
*/
223+
int readFrom(ByteBuffer buf);
224+
217225
/**
218226
* Read a single byte from this buffer.
219227
* @return next byte

common/buffers/src/main/java/io/helidon/common/buffers/CompositeArrayBufferData.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,6 +58,16 @@ public int readFrom(InputStream in) {
5858
throw new IllegalStateException("The composite buffer is fully written, cannot write additional bytes");
5959
}
6060

61+
@Override
62+
public int readFrom(ByteBuffer buf) {
63+
for (BufferData datum : data) {
64+
if (datum.capacity() > 0) {
65+
return datum.readFrom(buf);
66+
}
67+
}
68+
throw new IllegalStateException("The composite buffer is fully written, cannot write additional bytes");
69+
}
70+
6171
@Override
6272
public int read() {
6373
for (BufferData datum : data) {

common/buffers/src/main/java/io/helidon/common/buffers/CompositeListBufferData.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,6 +76,16 @@ public int readFrom(InputStream in) {
7676
throw new IllegalStateException("The composite buffer is fully written, cannot write additional bytes");
7777
}
7878

79+
@Override
80+
public int readFrom(ByteBuffer buf) {
81+
for (BufferData datum : data) {
82+
if (datum.capacity() > 0) {
83+
return datum.readFrom(buf);
84+
}
85+
}
86+
throw new IllegalStateException("The composite buffer is fully written, cannot write additional bytes");
87+
}
88+
7989
@Override
8090
public int read() {
8191
for (BufferData datum : data) {

common/buffers/src/main/java/io/helidon/common/buffers/DataReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ public boolean startsWithNewLine() {
168168
ensureAvailable();
169169
byte[] bytes = head.bytes;
170170
int pos = head.position;
171-
if (bytes[pos] == Bytes.CR_BYTE && ((pos + 1 < bytes.length) ? bytes[pos + 1] : head.next().peek()) == Bytes.LF_BYTE) {
172-
return true;
171+
if (pos + 1 < bytes.length) {
172+
return bytes[pos] == Bytes.CR_BYTE && bytes[pos + 1] == Bytes.LF_BYTE;
173173
}
174-
return false;
174+
return bytes[pos] == Bytes.CR_BYTE && head.next().peek() == Bytes.LF_BYTE;
175175
}
176176

177177
/**

common/buffers/src/main/java/io/helidon/common/buffers/FixedBufferData.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,6 +91,15 @@ public int readFrom(InputStream in) {
9191
return read;
9292
}
9393

94+
@Override
95+
public int readFrom(ByteBuffer buf) {
96+
int toRead = length - writePosition;
97+
int read = Math.min(toRead, buf.remaining());
98+
buf.get(bytes, writePosition, read);
99+
writePosition += read;
100+
return read;
101+
}
102+
94103
@Override
95104
public int read() {
96105
if (readPosition >= writePosition) {
@@ -129,7 +138,7 @@ public FixedBufferData write(int value) {
129138

130139
@Override
131140
public int writeTo(ByteBuffer writeBuffer, int length) {
132-
int toWrite = Math.min(writeBuffer.limit() - writeBuffer.position(), this.length - readPosition);
141+
int toWrite = Math.min(writeBuffer.limit() - writeBuffer.position(), writePosition - readPosition);
133142
toWrite = Math.min(toWrite, length);
134143
if (toWrite == 0) {
135144
return 0;

common/buffers/src/main/java/io/helidon/common/buffers/GrowingBufferData.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -83,6 +83,14 @@ public int readFrom(InputStream in) {
8383
}
8484
}
8585

86+
@Override
87+
public int readFrom(ByteBuffer buf) {
88+
int read = Math.min(buf.remaining(), bytes.length - writePosition);
89+
buf.get(bytes, writePosition, read);
90+
writePosition += read;
91+
return read;
92+
}
93+
8694
@Override
8795
public int read() {
8896
if (readPosition >= writePosition) {
@@ -120,8 +128,9 @@ public GrowingBufferData write(int value) {
120128
return this;
121129
}
122130

131+
@Override
123132
public int writeTo(ByteBuffer writeBuffer, int limit) {
124-
int toWrite = Math.min(writeBuffer.capacity(), length - readPosition);
133+
int toWrite = Math.min(writeBuffer.limit() - writeBuffer.position(), writePosition - readPosition);
125134
toWrite = Math.min(toWrite, limit);
126135
if (toWrite == 0) {
127136
return 0;

common/buffers/src/main/java/io/helidon/common/buffers/ReadOnlyArrayData.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,6 +58,11 @@ public int readFrom(InputStream in) {
5858
throw new UnsupportedOperationException();
5959
}
6060

61+
@Override
62+
public int readFrom(ByteBuffer buf) {
63+
throw new UnsupportedOperationException();
64+
}
65+
6166
@Override
6267
public int read() {
6368
if (position >= length) {

common/socket/src/main/java/io/helidon/common/socket/HelidonSocket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023 Oracle and/or its affiliates.
2+
* Copyright (c) 2022, 2025 Oracle and/or its affiliates.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,7 +48,9 @@ public interface HelidonSocket extends SocketContext, Supplier<byte[]> {
4848
*
4949
* @param buffer buffer to read to
5050
* @return number of bytes read
51+
* @deprecated this method is not used in Helidon, and will be removed
5152
*/
53+
@Deprecated(forRemoval = true, since = "4.4.0")
5254
int read(BufferData buffer);
5355

5456
/**

0 commit comments

Comments
 (0)