[uim-commit] r2105 - trunk/uim
ekato at freedesktop.org
ekato at freedesktop.org
Tue Nov 8 21:05:31 PST 2005
Author: ekato
Date: 2005-11-08 21:05:27 -0800 (Tue, 08 Nov 2005)
New Revision: 2105
Modified:
trunk/uim/skk.c
Log:
* uim/skk.c (skk_dic) : Rename skkserv_ok member to skkserv_state,
and use SKK_SERV_USE and SKK_SERV_CONNECTED mask for it.
(open_dic) : Use di->skkserv_state instead of di->skkserv_ok.
(search_line_from_server) : Retry skkserv connection if
disconnected or connection is not available.
(find_cand_array) : Use skkserv_state. Unset ca->is_used flag
if skkserv connection is not available.
(uim_plugin_instance_quit) : Use skkserv_state.
(open_skkserv) : Change return value as SKK_SERV_CONNECTED.
(reset_is_used_flag_of_cache) : New function.
(skkserv_disconnected) : New function.
Modified: trunk/uim/skk.c
===================================================================
--- trunk/uim/skk.c 2005-11-09 03:36:52 UTC (rev 2104)
+++ trunk/uim/skk.c 2005-11-09 05:05:27 UTC (rev 2105)
@@ -120,8 +120,8 @@
int cache_modified;
/* length of cached lines */
int cache_len;
- /* skkserv is initialized */
- int skkserv_ok;
+ /* skkserv related state */
+ int skkserv_state;
/* skkserv port number */
int skkserv_portnum;
} *skk_dic;
@@ -150,6 +150,8 @@
#define SKK_SERVICENAME "skkserv"
#define SKK_SERVER_HOST "localhost"
#define SKK_SERV_BUFSIZ 1024
+#define SKK_SERV_USE (1<<0)
+#define SKK_SERV_CONNECTED (1<<1)
static int skkservsock = -1;
static FILE *rserv, *wserv;
@@ -157,6 +159,7 @@
/* prototype */
static int open_skkserv(int portnum);
static void close_skkserv(void);
+static void skkserv_disconnected(struct dic_info *di);
static int
calc_line_len(const char *s)
@@ -227,9 +230,9 @@
di->skkserv_portnum = skkserv_portnum;
if (use_skkserv)
- di->skkserv_ok = open_skkserv(skkserv_portnum);
+ di->skkserv_state = SKK_SERV_USE | open_skkserv(skkserv_portnum);
else {
- di->skkserv_ok = 0;
+ di->skkserv_state = 0;
fd = open(fn, O_RDONLY);
if (fd != -1) {
if (fstat(fd, &st) != -1) {
@@ -667,23 +670,34 @@
char *line;
char *idx = alloca(strlen(s) + 2);
+ if (!(di->skkserv_state & SKK_SERV_CONNECTED)) {
+ if (!((di->skkserv_state |= open_skkserv(di->skkserv_portnum)) &
+ SKK_SERV_CONNECTED))
+ return NULL;
+ }
+
sprintf(idx, "%s%c", s, okuri_head);
fprintf(wserv, "1%s \n", idx);
ret = fflush(wserv);
if (ret != 0 && errno == EPIPE) {
- di->skkserv_ok = open_skkserv(di->skkserv_portnum);
+ skkserv_disconnected(di);
return NULL;
}
line = malloc(strlen(idx) + 2);
sprintf(line, "%s ", idx);
- read(skkservsock, &r, 1);
+
+ if (read(skkservsock, &r, 1) <= 0) {
+ skkserv_disconnected(di);
+ return NULL;
+ }
+
if (r == '1') { /* succeeded */
while (1) {
ret = read(skkservsock, &r, 1);
if (ret <= 0) {
- fprintf(stderr, "skkserv connection closed\n");
+ skkserv_disconnected(di);
return NULL;
}
@@ -774,7 +788,7 @@
sl = search_line_from_cache(di, s, okuri_head);
if (!sl) {
- if (di->skkserv_ok)
+ if (di->skkserv_state & SKK_SERV_USE)
sl = search_line_from_server(di, s, okuri_head);
else
sl = search_line_from_file(di, s, okuri_head);
@@ -793,9 +807,11 @@
merge_base_candidates_to_array(sl, ca);
ca->is_used = 1;
if (!from_file) {
- if (di->skkserv_ok)
+ if (di->skkserv_state & SKK_SERV_USE) {
sl_file = search_line_from_server(di, s, okuri_head);
- else
+ if (!(di->skkserv_state & SKK_SERV_CONNECTED))
+ ca->is_used = 0;
+ } else
sl_file = search_line_from_file(di, s, okuri_head);
merge_base_candidates_to_array(sl_file, ca);
free_skk_line(sl_file);
@@ -2999,7 +3015,7 @@
free_skk_line(tmp);
}
- if (skk_dic->skkserv_ok)
+ if (skk_dic->skkserv_state & SKK_SERV_CONNECTED)
close_skkserv();
free(skk_dic);
@@ -3061,7 +3077,7 @@
skkservsock = sock;
rserv = fdopen(sock, "r");
wserv = fdopen(sock, "w");
- return 1;
+ return SKK_SERV_CONNECTED;
}
static void
@@ -3072,3 +3088,26 @@
fflush(wserv);
}
}
+
+static void
+reset_is_used_flag_of_cache(struct dic_info *di)
+{
+ struct skk_line *sl;
+ int i;
+
+ sl = di->head.next;
+ while (sl) {
+ for (i = 0; i < sl->nr_cand_array; i++) {
+ struct skk_cand_array *ca = &sl->cands[i];
+ ca->is_used = 0;
+ }
+ sl = sl->next;
+ }
+}
+
+static void
+skkserv_disconnected(struct dic_info *di)
+{
+ di->skkserv_state &= ~SKK_SERV_CONNECTED;
+ reset_is_used_flag_of_cache(di);
+}
More information about the uim-commit
mailing list