Is there a way to close a Unix socket for only reading or writing?
Date : March 29 2020, 07:55 AM
help you fix your problem You can shutdown a socket for read or write using the second parameter to the method: shutdown(sock, SHUT_RD)
shutdown(sock, SHUT_WR)
|
Porting Windows socket program to Unix: Alternative for winsock32 APIs in unix
Tag : cpp , By : LinnheCreative
Date : March 29 2020, 07:55 AM
wish helps you You can track the closure event when performing reading. The socket is closed when read returns 0 (talking about "Berkeley sockets" of course). //EDIT: Use poll or select to wait for some event to occur (data arrival, socket closure ...).
|
why netty can not make a distinction between socket close and socket half close
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Nobody can tell the difference. Shutdown for output sends a FIN. Close sends a FIN, unless it has already been sent, i.e. by a shutdown. FIN appears at the receiver as the EOS (EOF) condition. The server got the FIN from the shutdown, saw that as EOS, closed the socket, your client got the FIN, saw that as EOS, closed the socket, and sent ... nothing to the server, because the FIN had already been sent.
|
Error: Get http://unix.socket/1.0: dial unix /var/snap/lxd/common/lxd/unix.socket: connect: permission denied
Date : March 29 2020, 07:55 AM
This might help you You will have to execute the following command in order to provide access to the current (non-root) user: newgrp lxd
sudo usermod -a -G lxd $(whoami)
/snap/bin/lxc query --wait -X GET /1.0
|
How to communicate a Rust and a Ruby process using a Unix socket pair
Date : March 29 2020, 07:55 AM
wish helps you The problem seems to be that Rust sets all file descriptors to be closed when a child is created by setting the FD_CLOEXEC flag. The only way to get around this seems to be using libc to call fcntl. Here’s some code that seems to work, but I don’t know Rust, so use at your own risk. Another issue you will have is you need to close the parent side of rust_socket after spawing the child, otherwise read_to_string will block forever waiting for the stream to be closed. You can do this with drop, but you will also need to use AsRawFd rather than IntoRawFd: use std::process::Command;
use std::os::unix::net::UnixStream;
use std::os::unix::io::AsRawFd;
use std::io::Read;
extern crate libc;
fn main() {
// Create the socket pair.
let (rust_socket, mut ruby_socket) = UnixStream::pair().unwrap();
// Unset FD_CLOEXEC on the socket to be passed to the child.
let fd = rust_socket.as_raw_fd();
unsafe {
let flags = libc::fcntl(fd, libc::F_GETFD);
libc::fcntl(fd, libc::F_SETFD, flags & !libc::FD_CLOEXEC);
}
// Spawn the child
let _output = Command::new("ruby")
.args(&["client.rb", &fd.to_string()])
.spawn();
// After spawning, close the parents side of rust_socket.
// If we use IntoRawFd, rust_socket would have been moved by this point
// so we need AsRawFD instead.
drop(rust_socket);
let mut response = String::new();
ruby_socket.read_to_string(&mut response).unwrap();
println!("Ruby said '{}'", response);
}
|