Files
neovim/src/nvim/event/socket.h
Marco Hinz 3efc82cbb2 Server: use uv_getaddrinfo() for $NVIM_LISTEN_ADDRESS
This change implicitly adds IPv6 support.

If the address contains ":", we try to use a TCP socket instead of a Unix domain
socket. Everything in front of the last occurrence of ":" is the hostname and
everything after it the port.

If the hostname lookup fails, we fall back to using a Unix domain socket.

If the port is empty ("localhost:"), a random port will be assigned.

Examples:

  NVIM_LISTEN_ADDRESS=localhost:12345 -> TCP (IPv4 or IPv6), port: 12345
  NVIM_LISTEN_ADDRESS=localhost:      -> TCP (IPv4 or IPv6), port: random (> 1024)
  NVIM_LISTEN_ADDRESS=localhost:0     -> TCP (IPv4 or IPv6), port: random (> 1024)
  NVIM_LISTEN_ADDRESS=localhost       -> Unix domain socket "localhost" in current dir
2017-05-22 01:05:39 +02:00

40 lines
912 B
C

#ifndef NVIM_EVENT_SOCKET_H
#define NVIM_EVENT_SOCKET_H
#include <uv.h>
#include "nvim/event/loop.h"
#include "nvim/event/rstream.h"
#include "nvim/event/wstream.h"
#define ADDRESS_MAX_SIZE 256
typedef struct socket_watcher SocketWatcher;
typedef void (*socket_cb)(SocketWatcher *watcher, int result, void *data);
typedef void (*socket_close_cb)(SocketWatcher *watcher, void *data);
struct socket_watcher {
// Pipe/socket path, or TCP address string
char addr[ADDRESS_MAX_SIZE];
// TCP server or unix socket (named pipe on Windows)
union {
struct {
uv_tcp_t handle;
struct addrinfo *addrinfo;
} tcp;
struct {
uv_pipe_t handle;
} pipe;
} uv;
uv_stream_t *stream;
void *data;
socket_cb cb;
socket_close_cb close_cb;
MultiQueue *events;
};
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "event/socket.h.generated.h"
#endif
#endif // NVIM_EVENT_SOCKET_H