socketry / async-io

Concurrent wrappers for native Ruby IO & Sockets.
MIT License
209 stars 28 forks source link

Async::IO::UNIXServer exited after a first message #60

Closed foi closed 1 year ago

foi commented 1 year ago

Hello! I have an issue: The same code for a tcp endpoint works as expected - server listens forever, for UnixServer - server exited after a first received message from a client.

server.rb

require "async/io"
require 'async/io/unix_socket'
require 'fileutils'

FileUtils.rm_f "./tmp.sock"
#@server = Async::IO::Endpoint.tcp('127.0.0.1', 1234)
@server = Async::IO::UNIXServer.wrap("./tmp.sock")
Async do |task|
   @server.accept do |client|
      a = client.read(6)
      client.send "elloh\n"
      client.close_write
    end
end

client.rb

require "socket"

# 10.times do
#   TCPSocket.open("127.0.0.1", 1234) do |socket|
#     socket << "hello\n"
#     p socket.read(6)
#     socket.close
#   end
# end

10.times do
  UNIXSocket.open("./tmp.sock") do |socket|
    socket << "hello\n"
    p socket.read(6)
    socket.close
  end
end

ruby 3.2.0

ioquatix commented 1 year ago

Here is a full example: https://github.com/socketry/async-io/commit/11cf87536580dcd085297e76d7f6ad3ed8ca4469

foi commented 1 year ago

Thank you very much! It works!