Skip to content

Composing event sources #207

@vikigenius

Description

@vikigenius

I am trying to create an event source for Unix domain sockets to use in an IPC Server. I tried to follow the zmq example in the book and have a working solution. But I have some design questions. Becasue there are some differences in the event sources between a ZMQ socket and a Unix socket.

With unix sockets the event sources are split into two. The listener that accepts connections. And the UnixStream that sends and receives messages.

Is it better to keep these sources separate or have a composed EventSource like this

pub struct IPCSource {
    socket_source: calloop::generic::Generic<calloop::generic::FdWrapper<UnixListener>>,
    connections: HashMap<&str, calloop::generic::Generic<calloop::generic::FdWrapper<UnixStream>>>,
}

Writ now I have two separate Event Sources one for the Listener and one for the UnixStream (there will be multiple UnixStreams because of multiple connections).

But I am wondering if I can gain some benefit by composing them like this or something similar?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions