Lines Matching refs:socket

55   ret->fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);  in socket_new()
84 void socket_free(socket_t* socket) { in socket_free() argument
85 if (!socket) return; in socket_free()
87 socket_unregister(socket); in socket_free()
88 close(socket->fd); in socket_free()
89 osi_free(socket); in socket_free()
92 bool socket_listen(const socket_t* socket, port_t port) { in socket_listen() argument
93 CHECK(socket != NULL); in socket_listen()
99 if (bind(socket->fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { in socket_listen()
105 if (listen(socket->fd, 10) == -1) { in socket_listen()
114 socket_t* socket_accept(const socket_t* socket) { in socket_accept() argument
115 CHECK(socket != NULL); in socket_accept()
118 OSI_NO_INTR(fd = accept(socket->fd, NULL, NULL)); in socket_accept()
130 ssize_t socket_read(const socket_t* socket, void* buf, size_t count) { in socket_read() argument
131 CHECK(socket != NULL); in socket_read()
135 OSI_NO_INTR(ret = recv(socket->fd, buf, count, MSG_DONTWAIT)); in socket_read()
140 ssize_t socket_write(const socket_t* socket, const void* buf, size_t count) { in socket_write() argument
141 CHECK(socket != NULL); in socket_write()
145 OSI_NO_INTR(ret = send(socket->fd, buf, count, MSG_DONTWAIT)); in socket_write()
150 ssize_t socket_write_and_transfer_fd(const socket_t* socket, const void* buf, in socket_write_and_transfer_fd() argument
152 CHECK(socket != NULL); in socket_write_and_transfer_fd()
155 if (fd == INVALID_FD) return socket_write(socket, buf, count); in socket_write_and_transfer_fd()
178 OSI_NO_INTR(ret = sendmsg(socket->fd, &msg, MSG_DONTWAIT)); in socket_write_and_transfer_fd()
184 ssize_t socket_bytes_available(const socket_t* socket) { in socket_bytes_available() argument
185 CHECK(socket != NULL); in socket_bytes_available()
188 if (ioctl(socket->fd, FIONREAD, &size) == -1) return -1; in socket_bytes_available()
192 void socket_register(socket_t* socket, reactor_t* reactor, void* context, in socket_register() argument
194 CHECK(socket != NULL); in socket_register()
197 socket_unregister(socket); in socket_register()
199 socket->read_ready = read_cb; in socket_register()
200 socket->write_ready = write_cb; in socket_register()
201 socket->context = context; in socket_register()
206 socket->reactor_object = in socket_register()
207 reactor_register(reactor, socket->fd, socket, read_fn, write_fn); in socket_register()
210 void socket_unregister(socket_t* socket) { in socket_unregister() argument
211 CHECK(socket != NULL); in socket_unregister()
213 if (socket->reactor_object) reactor_unregister(socket->reactor_object); in socket_unregister()
214 socket->reactor_object = NULL; in socket_unregister()
220 socket_t* socket = static_cast<socket_t*>(context); in internal_read_ready() local
221 socket->read_ready(socket, socket->context); in internal_read_ready()
227 socket_t* socket = static_cast<socket_t*>(context); in internal_write_ready() local
228 socket->write_ready(socket, socket->context); in internal_write_ready()