UnixSocket() throws IOException { channel = UnixSocketChannel.open(); }
private Socket createUnixDomainSocket() throws IOException { UnixSocketChannel channel = UnixSocketChannel.open(); return new BlockingUnixSocket(path, channel); }
@Override public UnixSocket createSocket(final HttpContext context) throws IOException { return UnixSocketChannel.open().socket(); }
public UnixDomainSocket(String ipcSocketPath, int bufferSize) { this.bufferSize = bufferSize; try { UnixSocketAddress address = new UnixSocketAddress(ipcSocketPath); channel = UnixSocketChannel.open(address); reader = new InputStreamReader(Channels.newInputStream(channel)); writer = new PrintWriter(Channels.newOutputStream(channel)); } catch (IOException e) { throw new RuntimeException( "Provided file socket cannot be opened: " + ipcSocketPath, e); } }
/** * Check whether we can connect to a local Unix socket * */ public static boolean canConnectUnixSocket(File path) { try (UnixSocketChannel channel = UnixSocketChannel.open()) { return channel.connect(new UnixSocketAddress(path)); } catch (IOException e) { return false; } } }
@Override @SuppressWarnings("unchecked") public void open() { try { setSocketChannel(UnixSocketChannel.open((UnixSocketAddress) address.getUnixSocketAddress())); } catch (IOException e) { close(); throw new MongoSocketOpenException("Exception opening socket", getAddress(), e); } } }
public UnixSocket() throws IOException { channel = UnixSocketChannel.open(); }
@Override public UnixSocket createSocket(final HttpContext context) throws IOException { return UnixSocketChannel.open().socket(); }
@Override public Socket createSocket(final HttpContext context) throws IOException { return UnixSocketChannel.open().socket(); }
public UnixDomainSocket(String ipcSocketPath, int bufferSize) { this.bufferSize = bufferSize; try { UnixSocketAddress address = new UnixSocketAddress(ipcSocketPath); UnixSocketChannel channel = UnixSocketChannel.open(address); reader = new InputStreamReader(Channels.newInputStream(channel)); writer = new PrintWriter(Channels.newOutputStream(channel)); } catch (IOException e) { throw new RuntimeException( "Provided file socket cannot be opened: " + ipcSocketPath, e); } }
public UnixDomainSocket(String ipcSocketPath, int bufferSize) { this.bufferSize = bufferSize; try { UnixSocketAddress address = new UnixSocketAddress(ipcSocketPath); channel = UnixSocketChannel.open(address); reader = new InputStreamReader(Channels.newInputStream(channel)); writer = new PrintWriter(Channels.newOutputStream(channel)); } catch (IOException e) { throw new RuntimeException( "Provided file socket cannot be opened: " + ipcSocketPath, e); } }
public UnixDomainSocket(String ipcSocketPath, int bufferSize) { this.bufferSize = bufferSize; try { UnixSocketAddress address = new UnixSocketAddress(ipcSocketPath); UnixSocketChannel channel = UnixSocketChannel.open(address); reader = new InputStreamReader(Channels.newInputStream(channel)); writer = new PrintWriter(Channels.newOutputStream(channel)); } catch (IOException e) { throw new RuntimeException( "Provided file socket cannot be opened: " + ipcSocketPath, e); } }
public UnixDomainSocket(String ipcSocketPath, int bufferSize) { this.bufferSize = bufferSize; try { UnixSocketAddress address = new UnixSocketAddress(ipcSocketPath); channel = UnixSocketChannel.open(address); reader = new InputStreamReader(Channels.newInputStream(channel)); writer = new PrintWriter(Channels.newOutputStream(channel)); } catch (IOException e) { throw new RuntimeException( "Provided file socket cannot be opened: " + ipcSocketPath, e); } }
public UnixDomainSocket(String ipcSocketPath, int bufferSize) { this.bufferSize = bufferSize; try { UnixSocketAddress address = new UnixSocketAddress(ipcSocketPath); UnixSocketChannel channel = UnixSocketChannel.open(address); reader = new InputStreamReader(Channels.newInputStream(channel)); writer = new PrintWriter(Channels.newOutputStream(channel)); } catch (IOException e) { throw new RuntimeException( "Provided file socket cannot be opened: " + ipcSocketPath, e); } }
public static void main(String[] args) throws IOException { java.io.File path = new java.io.File("/tmp/fubar.sock"); String data = "blah blah"; UnixSocketAddress address = new UnixSocketAddress(path); UnixSocketChannel channel = UnixSocketChannel.open(address); System.out.println("connected to " + channel.getRemoteSocketAddress()); PrintWriter w = new PrintWriter(Channels.newOutputStream(channel)); w.print(data); w.flush(); InputStreamReader r = new InputStreamReader(Channels.newInputStream(channel)); CharBuffer result = CharBuffer.allocate(1024); r.read(result); result.flip(); System.out.println("read from server: " + result.toString()); if (!result.toString().equals(data)) { System.out.println("ERROR: data mismatch"); } else { System.out.println("SUCCESS"); } } }
@Override public Socket createSocket() throws IOException { // Custom env variable for forcing unix socket boolean forceUnixSocket = System.getenv("CLOUD_SQL_FORCE_UNIX_SOCKET") != null; // If running on GAE Standard, connect with unix socket if (forceUnixSocket || runningOnGaeStandard()) { logger.info( String.format("Connecting to Cloud SQL instance [%s] via unix socket.", instanceName)); UnixSocketAddress socketAddress = new UnixSocketAddress(new File(CLOUD_SQL_PREFIX + instanceName + POSTGRES_SUFFIX)); return UnixSocketChannel.open(socketAddress).socket(); } // Default to SSL Socket logger.info( String.format("Connecting to Cloud SQL instance [%s] via ssl socket.", instanceName)); return SslSocketFactory.getInstance().create(instanceName, ipTypes); }
@Override public Socket createSocket() throws IOException { // Custom env variable for forcing unix socket boolean forceUnixSocket = System.getenv("CLOUD_SQL_FORCE_UNIX_SOCKET") != null; // If running on GAE Standard, connect with unix socket if (forceUnixSocket || runningOnGaeStandard()) { logger.info( String.format("Connecting to Cloud SQL instance [%s] via unix socket.", instanceName)); UnixSocketAddress socketAddress = new UnixSocketAddress(new File(CLOUD_SQL_PREFIX + instanceName + POSTGRES_SUFFIX)); return UnixSocketChannel.open(socketAddress).socket(); } // Default to SSL Socket logger.info( String.format("Connecting to Cloud SQL instance [%s] via ssl socket.", instanceName)); return SslSocketFactory.getInstance().create(instanceName, ipTypes); }
protected ChannelDescriptor initChannel(Ruby runtime) { Channel channel; try { if(soType == Sock.SOCK_STREAM) { if (soProtocol == ProtocolFamily.PF_UNIX || soProtocol == ProtocolFamily.PF_LOCAL) { channel = UnixSocketChannel.open(); } else if (soProtocol == ProtocolFamily.PF_INET || soProtocol == ProtocolFamily.PF_INET6 || soProtocol == ProtocolFamily.PF_UNSPEC) { channel = SocketChannel.open(); } else { throw runtime.newArgumentError("unsupported protocol family `" + soProtocol + "'"); } } else if(soType == Sock.SOCK_DGRAM) { channel = DatagramChannel.open(); } else { throw runtime.newArgumentError("unsupported socket type `" + soType + "'"); } return newChannelDescriptor(runtime, channel); } catch(IOException e) { throw SocketUtils.sockerr(runtime, "initialize: " + e.toString()); } }
@Override @SuppressWarnings("unchecked") public void open() { try { setSocketChannel(UnixSocketChannel.open((UnixSocketAddress) address.getUnixSocketAddress())); } catch (IOException e) { close(); throw new MongoSocketOpenException("Exception opening socket", getAddress(), e); } } }
protected void init_unixsock(Ruby runtime, IRubyObject _path, boolean server) { ByteList path = _path.convertToString().getByteList(); String fpath = Helpers.decodeByteList(runtime, path); int maxSize = 103; // Max size from Darwin, lowest common value we know of if (fpath.length() > 103) { throw runtime.newArgumentError("too long unix socket path (max: " + maxSize + "bytes)"); } try { if (server) { UnixServerSocketChannel channel = UnixServerSocketChannel.open(); UnixServerSocket socket = channel.socket(); // TODO: listen backlog socket.bind(new UnixSocketAddress(new File(fpath))); init_sock(runtime, channel, fpath); } else { File fpathFile = new File(fpath); if (!fpathFile.exists()) { throw runtime.newErrnoENOENTError("unix socket"); } UnixSocketChannel channel = UnixSocketChannel.open(); channel.connect(new UnixSocketAddress(fpathFile)); init_sock(runtime, channel); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }