[uim-commit] r1154 - trunk/uim
tkng at freedesktop.org
tkng at freedesktop.org
Sun Aug 7 20:19:01 EST 2005
Author: tkng
Date: 2005-08-07 03:18:58 -0700 (Sun, 07 Aug 2005)
New Revision: 1154
Modified:
trunk/uim/uim-helper-server.c
Log:
* uim/uim-helper-server.c: This commit aims for refactoring.
-(accept_new_connection): New function.
-(uim_helper_server_process_connection): Replaced long acception code
with accept_new_connection.
Modified: trunk/uim/uim-helper-server.c
===================================================================
--- trunk/uim/uim-helper-server.c 2005-08-07 10:10:01 UTC (rev 1153)
+++ trunk/uim/uim-helper-server.c 2005-08-07 10:18:58 UTC (rev 1154)
@@ -74,7 +74,7 @@
static char read_buf[BUFFER_SIZE];
/*
- prepare file descriptor.
+ initialize server's file descriptor.
*/
static int
init_server_fd(char *path)
@@ -216,6 +216,51 @@
}
+static uim_bool
+accept_new_connection(int server_fd)
+{
+ struct sockaddr_un clientsoc;
+ socklen_t len = sizeof(clientsoc);
+ int new_fd;
+ int flag;
+ struct client *cl;
+ new_fd = accept(server_fd, (struct sockaddr *)&clientsoc, &len);
+
+ if (new_fd < 0) {
+ perror("accpet failed");
+ return UIM_FALSE;
+ }
+
+ if ((flag = fcntl(new_fd, F_GETFL)) == -1) {
+ close(new_fd);
+ return UIM_FALSE;
+ }
+
+ flag |= O_NONBLOCK;
+ if (fcntl(new_fd, F_SETFL, flag) == -1) {
+ close(new_fd);
+ return UIM_FALSE;
+ }
+
+ cl = get_unused_client();
+ if (!cl) {
+ close(new_fd);
+ return UIM_FALSE;
+ }
+ cl->fd = new_fd;
+#ifdef LOCAL_CREDS /* for NetBSD */
+ {
+ char buf[1] = { '\0' };
+ write(cl->fd, buf, 1);
+ }
+#endif
+ FD_SET(cl->fd, &s_fdset_read);
+ if (cl->fd > s_max_fd)
+ s_max_fd = cl->fd;
+
+ return UIM_TRUE;
+}
+
/* FIXME: This function is too long to read... */
static void
uim_helper_server_process_connection(int server_fd)
@@ -225,6 +270,7 @@
fd_set writefds;
while (1) {
+ /* Could we replace this memcpy with direct assignment? */
memcpy(&readfds, &s_fdset_read, sizeof(fd_set));
memcpy(&writefds, &s_fdset_write, sizeof(fd_set));
@@ -237,44 +283,11 @@
/* for accept new connection */
if (FD_ISSET(server_fd, &readfds)) {
- struct sockaddr_un clientsoc;
- socklen_t len = sizeof(clientsoc);
- int new_fd;
- int flag;
- struct client *cl;
- new_fd = accept(server_fd, (struct sockaddr *)&clientsoc, &len);
-
- if (new_fd < 0) {
- perror("accpet failed");
- continue;
+ uim_bool accepted;
+ accepted = accept_new_connection(server_fd);
+ if(accepted == UIM_FALSE) {
+ continue; /* acception failed, go next loop without message processing. */
}
-
- if ((flag = fcntl(new_fd, F_GETFL)) == -1) {
- close(new_fd);
- continue;
- }
-
- flag |= O_NONBLOCK;
- if (fcntl(new_fd, F_SETFL, flag) == -1) {
- close(new_fd);
- continue;
- }
-
- cl = get_unused_client();
- if (!cl) {
- close(new_fd);
- continue;
- }
- cl->fd = new_fd;
-#ifdef LOCAL_CREDS /* for NetBSD */
- {
- char buf[1] = { '\0' };
- write(cl->fd, buf, 1);
- }
-#endif
- FD_SET(cl->fd, &s_fdset_read);
- if (cl->fd > s_max_fd)
- s_max_fd = cl->fd;
} else {
/* check data to write and from clients reached */
for (i = 0; i < nr_client_slots; i++) {
More information about the uim-commit
mailing list