# endif
# ifdef FEAT_SOCKETSERVER
- if (socket_server_fd != -1)
+ if (socket_server_idx >= 0)
{
if (fds[socket_server_idx].revents & POLLIN)
- socket_server_accept_client();
+ {
+ if (socket_server_accept_client() == FAIL)
+ socket_server_uninit();
+ }
else if (fds[socket_server_idx].revents & (POLLHUP | POLLERR))
socket_server_uninit();
}
-
# endif
# ifdef FEAT_WAYLAND_CLIPBOARD
# endif
# ifdef FEAT_SOCKETSERVER
- if (socket_server_fd != -1 && ret > 0)
- {
- if (FD_ISSET(socket_server_fd, &rfds))
- socket_server_accept_client();
- else if (FD_ISSET(socket_server_fd, &efds))
- socket_server_uninit();
- }
+ if (ret > 0 && socket_server_fd != -1
+ && FD_ISSET(socket_server_fd, &rfds)
+ && socket_server_accept_client() == FAIL)
+ socket_server_uninit();
# endif
# ifdef FEAT_WAYLAND_CLIPBOARD
/*
* Called when the server has received a new command. If so, parse it and do the
- * stuff it says, and possibly send back a reply.
+ * stuff it says, and possibly send back a reply. Returns OK if client was
+ * accepted, else FAIL.
*/
- void
+ int
socket_server_accept_client(void)
{
int fd = accept(socket_server_fd, NULL, NULL);
ss_cmd_T cmd;
if (fd == -1)
- return;
+ return FAIL;
if (socket_server_decode_cmd(&cmd, fd, 1000) == FAIL)
goto exit;
exit:
close(fd);
+ return OK;
}
/*
size_t sz;
char_u *final;
char_u *path;
- struct timeval start, now;
-
+#ifdef ELAPSED_FUNC
+ elapsed_T start_tv;
+#endif
if (!socket_server_valid())
{
socket_server_init_pending_cmd(&pending);
- gettimeofday(&start, NULL);
+#ifdef ELAPSED_FUNC
+ ELAPSED_INIT(start_tv);
+#endif
// Wait for server to send back result
while (socket_server_dispatch(500) >= 0)
if (pending.result != NULL)
break;
- gettimeofday(&now, NULL);
-
- if ((now.tv_sec * 1000000 + now.tv_usec) -
- (start.tv_sec * 1000000 + start.tv_usec) >=
- (timeout > 0 ? timeout * 1000 : 1000 * 1000))
+ if (ELAPSED_FUNC(start_tv) >= (timeout > 0 ? timeout : 1000))
break;
}
* success and FAIL on failure. Timeout is in milliseconds
*/
int
-socket_server_read_reply(char_u *client, char_u **str, int timeout)
+socket_server_read_reply(char_u *client, char_u **str, int timeout UNUSED)
{
- ss_reply_T *reply = NULL;
- struct timeval start, now;
+ ss_reply_T *reply = NULL;
+#ifdef ELAPSED_FUNC
+ elapsed_T start_tv;
+#endif
if (!socket_server_name_is_valid(client))
return -1;
if (!socket_server_valid())
return -1;
+#ifdef ELAPSED_FUNC
if (timeout > 0)
- gettimeofday(&start, NULL);
+ ELAPSED_INIT(start_tv);
+#endif
// Try seeing if there already is a reply in the queue
goto get_reply;
{
int fd;
- if (timeout > 0)
- gettimeofday(&now, NULL);
-
- if (timeout > 0)
- if ((now.tv_sec * 1000000 + now.tv_usec) -
- (start.tv_sec * 1000000 + start.tv_usec) >= timeout * 1000)
- break;
+#ifdef ELAPSED_FUNC
+ if (timeout > 0 && ELAPSED_FUNC(start_tv) >= timeout)
+ break;
+#endif
get_reply:
reply = socket_server_get_reply(client, NULL);
size_t total_r = 0;
char_u *buf;
char_u *cur;
- struct timeval start, now;
+#ifdef ELAPSED_FUNC
+ elapsed_T start_tv;
+#endif
// We also poll the socket server listening file descriptor to handle
// recursive remote calls between Vim instances, such as when one Vim
// want to free an uninitialized pointer.
memset(cmd, 0, sizeof(*cmd));
- gettimeofday(&start, NULL);
+#ifdef ELAPSED_FUNC
+ ELAPSED_INIT(start_tv);
+#endif
while (TRUE)
{
total_r += r;
continue_loop:
- gettimeofday(&now, NULL);
-
- if ((now.tv_sec * 1000000 + now.tv_usec) -
- (start.tv_sec * 1000000 + start.tv_usec) >= timeout * 1000)
+#ifdef ELAPSED_FUNC
+ if (ELAPSED_FUNC(start_tv) >= timeout)
goto fail;
+#endif
}
// Parse message data
{
char_u *cur = data;
size_t total_w = 0;
- struct timeval start, now;
+#ifdef ELAPSED_FUNC
+ elapsed_T start_tv;
+#endif
#ifndef HAVE_SELECT
struct pollfd pfd;
FD_SET(socket_fd, &wfds);
#endif
- gettimeofday(&start, NULL);
+#ifdef ELAPSED_FUNC
+ ELAPSED_INIT(start_tv);
+#endif
while (total_w < sz)
{
total_w += written;
-
continue_loop:
- gettimeofday(&now, NULL);
-
- if ((now.tv_sec * 1000000 + now.tv_usec) -
- (start.tv_sec * 1000000 + start.tv_usec) >= timeout * 1000)
+#ifdef ELAPSED_FUNC
+ if (ELAPSED_FUNC(start_tv) >= timeout)
return FAIL;
+#endif
}
return OK;