Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b7ad96e

Browse filesBrowse files
committed
wip
1 parent 8cf84fe commit b7ad96e
Copy full SHA for b7ad96e

3 files changed

+450-6Lines changed: 450 additions & 6 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/main/java/com/github/dockerjava/netty/DockerCmdExecFactoryImpl.java‎

Copy file name to clipboardExpand all lines: src/main/java/com/github/dockerjava/netty/DockerCmdExecFactoryImpl.java
+26-6Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,18 @@
55
import java.io.IOException;
66
import java.net.InetAddress;
77
import java.net.InetSocketAddress;
8+
import java.net.ProtocolFamily;
89
import java.net.SocketAddress;
10+
import java.nio.channels.DatagramChannel;
11+
import java.nio.channels.Pipe;
12+
import java.nio.channels.SelectionKey;
13+
import java.nio.channels.Selector;
14+
import java.nio.channels.ServerSocketChannel;
15+
import java.nio.channels.spi.AbstractSelectableChannel;
16+
import java.nio.channels.spi.AbstractSelector;
17+
import java.nio.channels.spi.SelectorProvider;
918
import java.security.Security;
19+
import java.util.Set;
1020

1121
import javax.net.ssl.SSLContext;
1222
import javax.net.ssl.SSLEngine;
@@ -132,6 +142,8 @@
132142
import io.netty.handler.ssl.SslHandler;
133143
import io.netty.util.concurrent.DefaultThreadFactory;
134144
import jnr.enxio.channels.NativeSelectorProvider;
145+
import jnr.unixsocket.UnixSocketAddress;
146+
import jnr.unixsocket.UnixSocketChannel;
135147
import unisockets.Addr;
136148

137149
/**
@@ -220,16 +232,20 @@ private class UnixDomainSocketInitializer implements NettyInitializer {
220232

221233
@Override
222234
public EventLoopGroup init(Bootstrap bootstrap, DockerClientConfig dockerClientConfig) {
223-
235+
final SelectorProvider nativeSelectorProvider = NativeSelectorProvider.getInstance();
236+
224237
EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(0,
225-
new DefaultThreadFactory(threadPrefix), NativeSelectorProvider.getInstance());
238+
new DefaultThreadFactory(threadPrefix), nativeSelectorProvider);
226239

227240
ChannelFactory<NioSocketChannel> factory = new ChannelFactory<NioSocketChannel>() {
228241

229242
@Override
230243
public NioSocketChannel newChannel() {
231-
unisockets.SocketChannel socketChannel = unisockets.SocketChannel.open(path);
232-
return new NioSocketChannel(socketChannel);
244+
try {
245+
return new NioSocketChannel(UnixSocketChannel.create());
246+
} catch (IOException e) {
247+
throw new RuntimeException();
248+
}
233249
}
234250
};
235251

@@ -247,9 +263,13 @@ protected void initChannel(final SocketChannel channel) throws Exception {
247263
@Override
248264
public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException {
249265

250-
Addr addr = Addr.apply(new java.io.File("/var/run/docker.sock"));
266+
if(!path.exists()) {
267+
throw new RuntimeException("socket not found: " + path);
268+
}
269+
270+
UnixSocketAddress socket = new UnixSocketAddress(path);
251271

252-
return (DuplexChannel) bootstrap.connect(addr).sync().channel();
272+
return (DuplexChannel) bootstrap.connect(socket).sync().channel();
253273
}
254274
}
255275

Collapse file
+115Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
* Copyright (C) 2008 Wayne Meissner
3+
*
4+
* This file is part of the JNR project.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package jnr.enxio.channels;
20+
21+
import java.io.IOException;
22+
import java.nio.ByteBuffer;
23+
import java.nio.channels.ByteChannel;
24+
import java.nio.channels.SocketChannel;
25+
import java.nio.channels.spi.SelectorProvider;
26+
27+
import jnr.constants.platform.Shutdown;
28+
29+
public abstract class NativeSocketChannel extends SocketChannel
30+
implements ByteChannel, NativeSelectableChannel {
31+
32+
private int fd = -1;
33+
34+
public NativeSocketChannel(int fd) {
35+
this(NativeSelectorProvider.getInstance(), fd);
36+
}
37+
38+
public NativeSocketChannel() {
39+
super(NativeSelectorProvider.getInstance());
40+
}
41+
42+
NativeSocketChannel(SelectorProvider provider, int fd) {
43+
super(provider);
44+
this.fd = fd;
45+
}
46+
47+
public void setFD(int fd) {
48+
this.fd = fd;
49+
}
50+
51+
@Override
52+
protected void implCloseSelectableChannel() throws IOException {
53+
Native.close(fd);
54+
}
55+
56+
@Override
57+
protected void implConfigureBlocking(boolean block) throws IOException {
58+
Native.setBlocking(fd, block);
59+
}
60+
61+
public final int getFD() {
62+
return fd;
63+
}
64+
65+
public int read(ByteBuffer dst) throws IOException {
66+
int n = Native.read(fd, dst);
67+
switch (n) {
68+
case 0:
69+
return -1;
70+
71+
case -1:
72+
switch (Native.getLastError()) {
73+
case EAGAIN:
74+
case EWOULDBLOCK:
75+
return 0;
76+
77+
default:
78+
throw new IOException(Native.getLastErrorString());
79+
}
80+
81+
default:
82+
return n;
83+
}
84+
}
85+
86+
public int write(ByteBuffer src) throws IOException {
87+
int n = Native.write(fd, src);
88+
if (n < 0) {
89+
throw new IOException(Native.getLastErrorString());
90+
}
91+
92+
return n;
93+
}
94+
95+
protected void _shutdownInput() throws IOException {
96+
int n = Native.shutdown(fd, SHUT_RD);
97+
if (n < 0) {
98+
throw new IOException(Native.getLastErrorString());
99+
}
100+
}
101+
102+
103+
104+
protected void _shutdownOutput() throws IOException {
105+
int n = Native.shutdown(fd, SHUT_WR);
106+
if (n < 0) {
107+
throw new IOException(Native.getLastErrorString());
108+
}
109+
}
110+
111+
private final static int SHUT_RD = Shutdown.SHUT_RD.intValue();
112+
private final static int SHUT_WR = Shutdown.SHUT_WR.intValue();
113+
114+
115+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.