Mercurial > vim
comparison src/channel.c @ 11937:c893d6c00497 v8.0.0848
patch 8.0.0848: using multiple ch_log functions is clumsy
commit https://github.com/vim/vim/commit/2f3a90a3bd8505728c0b6d9ac3515f64ee19b357
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 3 14:49:29 2017 +0200
patch 8.0.0848: using multiple ch_log functions is clumsy
Problem: Using multiple ch_log functions is clumsy.
Solution: Use variable arguments. (Ozaki Kiichi, closes https://github.com/vim/vim/issues/1919)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 03 Aug 2017 15:00:05 +0200 |
parents | d033653d3df8 |
children | ef1febf04d03 |
comparison
equal
deleted
inserted
replaced
11936:84e482f5ae52 | 11937:c893d6c00497 |
---|---|
157 } | 157 } |
158 | 158 |
159 static int did_log_msg = TRUE; | 159 static int did_log_msg = TRUE; |
160 | 160 |
161 void | 161 void |
162 ch_log(channel_T *ch, char *msg) | 162 ch_log(channel_T *ch, const char *fmt, ...) |
163 { | 163 { |
164 if (log_fd != NULL) | 164 if (log_fd != NULL) |
165 { | 165 { |
166 va_list ap; | |
167 | |
166 ch_log_lead("", ch); | 168 ch_log_lead("", ch); |
167 fputs(msg, log_fd); | 169 va_start(ap, fmt); |
170 vfprintf(log_fd, fmt, ap); | |
171 va_end(ap); | |
168 fputc('\n', log_fd); | 172 fputc('\n', log_fd); |
169 fflush(log_fd); | 173 fflush(log_fd); |
170 did_log_msg = TRUE; | 174 did_log_msg = TRUE; |
171 } | 175 } |
172 } | 176 } |
173 | 177 |
174 void | 178 static void |
175 ch_logn(channel_T *ch, char *msg, int nr) | 179 ch_error(channel_T *ch, const char *fmt, ...) |
176 { | 180 { |
177 if (log_fd != NULL) | 181 if (log_fd != NULL) |
178 { | 182 { |
179 ch_log_lead("", ch); | 183 va_list ap; |
180 fprintf(log_fd, msg, nr); | 184 |
181 fputc('\n', log_fd); | |
182 fflush(log_fd); | |
183 did_log_msg = TRUE; | |
184 } | |
185 } | |
186 | |
187 void | |
188 ch_logs(channel_T *ch, char *msg, char *name) | |
189 { | |
190 if (log_fd != NULL) | |
191 { | |
192 ch_log_lead("", ch); | |
193 fprintf(log_fd, msg, name); | |
194 fputc('\n', log_fd); | |
195 fflush(log_fd); | |
196 did_log_msg = TRUE; | |
197 } | |
198 } | |
199 | |
200 static void | |
201 ch_logsn(channel_T *ch, char *msg, char *name, int nr) | |
202 { | |
203 if (log_fd != NULL) | |
204 { | |
205 ch_log_lead("", ch); | |
206 fprintf(log_fd, msg, name, nr); | |
207 fputc('\n', log_fd); | |
208 fflush(log_fd); | |
209 did_log_msg = TRUE; | |
210 } | |
211 } | |
212 | |
213 static void | |
214 ch_error(channel_T *ch, char *msg) | |
215 { | |
216 if (log_fd != NULL) | |
217 { | |
218 ch_log_lead("ERR ", ch); | 185 ch_log_lead("ERR ", ch); |
219 fputs(msg, log_fd); | 186 va_start(ap, fmt); |
220 fputc('\n', log_fd); | 187 vfprintf(log_fd, fmt, ap); |
221 fflush(log_fd); | 188 va_end(ap); |
222 did_log_msg = TRUE; | |
223 } | |
224 } | |
225 | |
226 static void | |
227 ch_errorn(channel_T *ch, char *msg, int nr) | |
228 { | |
229 if (log_fd != NULL) | |
230 { | |
231 ch_log_lead("ERR ", ch); | |
232 fprintf(log_fd, msg, nr); | |
233 fputc('\n', log_fd); | |
234 fflush(log_fd); | |
235 did_log_msg = TRUE; | |
236 } | |
237 } | |
238 | |
239 static void | |
240 ch_errors(channel_T *ch, char *msg, char *arg) | |
241 { | |
242 if (log_fd != NULL) | |
243 { | |
244 ch_log_lead("ERR ", ch); | |
245 fprintf(log_fd, msg, arg); | |
246 fputc('\n', log_fd); | 189 fputc('\n', log_fd); |
247 fflush(log_fd); | 190 fflush(log_fd); |
248 did_log_msg = TRUE; | 191 did_log_msg = TRUE; |
249 } | 192 } |
250 } | 193 } |
511 channel_T *channel; | 454 channel_T *channel; |
512 ch_part_T part; | 455 ch_part_T part; |
513 | 456 |
514 channel = channel_fd2channel(fd, &part); | 457 channel = channel_fd2channel(fd, &part); |
515 if (channel == NULL) | 458 if (channel == NULL) |
516 ch_errorn(NULL, "Channel for fd %d not found", fd); | 459 ch_error(NULL, "Channel for fd %d not found", fd); |
517 else | 460 else |
518 channel_read(channel, part, "channel_read_fd"); | 461 channel_read(channel, part, "channel_read_fd"); |
519 } | 462 } |
520 #endif | 463 #endif |
521 | 464 |
755 fcntl(sd, F_SETFL, O_NONBLOCK) < 0 | 698 fcntl(sd, F_SETFL, O_NONBLOCK) < 0 |
756 #endif | 699 #endif |
757 ) | 700 ) |
758 { | 701 { |
759 SOCK_ERRNO; | 702 SOCK_ERRNO; |
760 ch_errorn(channel, | 703 ch_error(channel, |
761 "channel_open: Connect failed with errno %d", errno); | 704 "channel_open: Connect failed with errno %d", errno); |
762 sock_close(sd); | 705 sock_close(sd); |
763 channel_free(channel); | 706 channel_free(channel); |
764 return NULL; | 707 return NULL; |
765 } | 708 } |
766 } | 709 } |
767 | 710 |
768 /* Try connecting to the server. */ | 711 /* Try connecting to the server. */ |
769 ch_logsn(channel, "Connecting to %s port %d", hostname, port); | 712 ch_log(channel, "Connecting to %s port %d", hostname, port); |
770 ret = connect(sd, (struct sockaddr *)&server, sizeof(server)); | 713 ret = connect(sd, (struct sockaddr *)&server, sizeof(server)); |
771 | 714 |
772 if (ret == 0) | 715 if (ret == 0) |
773 /* The connection could be established. */ | 716 /* The connection could be established. */ |
774 break; | 717 break; |
779 #ifdef EINPROGRESS | 722 #ifdef EINPROGRESS |
780 && errno != EINPROGRESS | 723 && errno != EINPROGRESS |
781 #endif | 724 #endif |
782 )) | 725 )) |
783 { | 726 { |
784 ch_errorn(channel, | 727 ch_error(channel, |
785 "channel_open: Connect failed with errno %d", errno); | 728 "channel_open: Connect failed with errno %d", errno); |
786 PERROR(_(e_cannot_connect)); | 729 PERROR(_(e_cannot_connect)); |
787 sock_close(sd); | 730 sock_close(sd); |
788 channel_free(channel); | 731 channel_free(channel); |
789 return NULL; | 732 return NULL; |
816 tv.tv_sec = waitnow / 1000; | 759 tv.tv_sec = waitnow / 1000; |
817 tv.tv_usec = (waitnow % 1000) * 1000; | 760 tv.tv_usec = (waitnow % 1000) * 1000; |
818 #ifndef WIN32 | 761 #ifndef WIN32 |
819 gettimeofday(&start_tv, NULL); | 762 gettimeofday(&start_tv, NULL); |
820 #endif | 763 #endif |
821 ch_logn(channel, | 764 ch_log(channel, |
822 "Waiting for connection (waiting %d msec)...", waitnow); | 765 "Waiting for connection (waiting %d msec)...", waitnow); |
823 ret = select((int)sd + 1, &rfds, &wfds, NULL, &tv); | 766 ret = select((int)sd + 1, &rfds, &wfds, NULL, &tv); |
824 | 767 |
825 if (ret < 0) | 768 if (ret < 0) |
826 { | 769 { |
827 SOCK_ERRNO; | 770 SOCK_ERRNO; |
828 ch_errorn(channel, | 771 ch_error(channel, |
829 "channel_open: Connect failed with errno %d", errno); | 772 "channel_open: Connect failed with errno %d", errno); |
830 PERROR(_(e_cannot_connect)); | 773 PERROR(_(e_cannot_connect)); |
831 sock_close(sd); | 774 sock_close(sd); |
832 channel_free(channel); | 775 channel_free(channel); |
833 return NULL; | 776 return NULL; |
862 # ifdef EINPROGRESS | 805 # ifdef EINPROGRESS |
863 && so_error != EINPROGRESS | 806 && so_error != EINPROGRESS |
864 # endif | 807 # endif |
865 )) | 808 )) |
866 { | 809 { |
867 ch_errorn(channel, | 810 ch_error(channel, |
868 "channel_open: Connect failed with errno %d", | 811 "channel_open: Connect failed with errno %d", |
869 so_error); | 812 so_error); |
870 PERROR(_(e_cannot_connect)); | 813 PERROR(_(e_cannot_connect)); |
871 sock_close(sd); | 814 sock_close(sd); |
872 channel_free(channel); | 815 channel_free(channel); |
1075 if (job->jv_in_buf != NULL) | 1018 if (job->jv_in_buf != NULL) |
1076 { | 1019 { |
1077 chanpart_T *in_part = &channel->ch_part[PART_IN]; | 1020 chanpart_T *in_part = &channel->ch_part[PART_IN]; |
1078 | 1021 |
1079 set_bufref(&in_part->ch_bufref, job->jv_in_buf); | 1022 set_bufref(&in_part->ch_bufref, job->jv_in_buf); |
1080 ch_logs(channel, "reading from buffer '%s'", | 1023 ch_log(channel, "reading from buffer '%s'", |
1081 (char *)in_part->ch_bufref.br_buf->b_ffname); | 1024 (char *)in_part->ch_bufref.br_buf->b_ffname); |
1082 if (options->jo_set & JO_IN_TOP) | 1025 if (options->jo_set & JO_IN_TOP) |
1083 { | 1026 { |
1084 if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT)) | 1027 if (options->jo_in_top == 0 && !(options->jo_set & JO_IN_BOT)) |
1085 { | 1028 { |
1242 { | 1185 { |
1243 EMSG(_(e_modifiable)); | 1186 EMSG(_(e_modifiable)); |
1244 } | 1187 } |
1245 else | 1188 else |
1246 { | 1189 { |
1247 ch_logs(channel, "writing out to buffer '%s'", | 1190 ch_log(channel, "writing out to buffer '%s'", |
1248 (char *)buf->b_ffname); | 1191 (char *)buf->b_ffname); |
1249 set_bufref(&channel->ch_part[PART_OUT].ch_bufref, buf); | 1192 set_bufref(&channel->ch_part[PART_OUT].ch_bufref, buf); |
1250 } | 1193 } |
1251 } | 1194 } |
1252 } | 1195 } |
1285 { | 1228 { |
1286 EMSG(_(e_modifiable)); | 1229 EMSG(_(e_modifiable)); |
1287 } | 1230 } |
1288 else | 1231 else |
1289 { | 1232 { |
1290 ch_logs(channel, "writing err to buffer '%s'", | 1233 ch_log(channel, "writing err to buffer '%s'", |
1291 (char *)buf->b_ffname); | 1234 (char *)buf->b_ffname); |
1292 set_bufref(&channel->ch_part[PART_ERR].ch_bufref, buf); | 1235 set_bufref(&channel->ch_part[PART_ERR].ch_bufref, buf); |
1293 } | 1236 } |
1294 } | 1237 } |
1295 } | 1238 } |
1458 write_buf_line(buf, lnum, channel); | 1401 write_buf_line(buf, lnum, channel); |
1459 ++written; | 1402 ++written; |
1460 } | 1403 } |
1461 | 1404 |
1462 if (written == 1) | 1405 if (written == 1) |
1463 ch_logn(channel, "written line %d to channel", (int)lnum - 1); | 1406 ch_log(channel, "written line %d to channel", (int)lnum - 1); |
1464 else if (written > 1) | 1407 else if (written > 1) |
1465 ch_logn(channel, "written %d lines to channel", written); | 1408 ch_log(channel, "written %d lines to channel", written); |
1466 | 1409 |
1467 in_part->ch_buf_top = lnum; | 1410 in_part->ch_buf_top = lnum; |
1468 if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot) | 1411 if (lnum > buf->b_ml.ml_line_count || lnum > in_part->ch_buf_bot) |
1469 { | 1412 { |
1470 /* Writing is done, no longer need the buffer. */ | 1413 /* Writing is done, no longer need the buffer. */ |
1473 | 1416 |
1474 /* Close the pipe/socket, so that the other side gets EOF. */ | 1417 /* Close the pipe/socket, so that the other side gets EOF. */ |
1475 ch_close_part(channel, PART_IN); | 1418 ch_close_part(channel, PART_IN); |
1476 } | 1419 } |
1477 else | 1420 else |
1478 ch_logn(channel, "Still %d more lines to write", | 1421 ch_log(channel, "Still %d more lines to write", |
1479 buf->b_ml.ml_line_count - lnum + 1); | 1422 buf->b_ml.ml_line_count - lnum + 1); |
1480 } | 1423 } |
1481 | 1424 |
1482 /* | 1425 /* |
1483 * Handle buffer "buf" being freed, remove it from any channels. | 1426 * Handle buffer "buf" being freed, remove it from any channels. |
1493 { | 1436 { |
1494 chanpart_T *ch_part = &channel->ch_part[part]; | 1437 chanpart_T *ch_part = &channel->ch_part[part]; |
1495 | 1438 |
1496 if (ch_part->ch_bufref.br_buf == buf) | 1439 if (ch_part->ch_bufref.br_buf == buf) |
1497 { | 1440 { |
1498 ch_logs(channel, "%s buffer has been wiped out", | 1441 ch_log(channel, "%s buffer has been wiped out", |
1499 part_names[part]); | 1442 part_names[part]); |
1500 ch_part->ch_bufref.br_buf = NULL; | 1443 ch_part->ch_bufref.br_buf = NULL; |
1501 } | 1444 } |
1502 } | 1445 } |
1503 } | 1446 } |
1554 write_buf_line(buf, lnum, channel); | 1497 write_buf_line(buf, lnum, channel); |
1555 ++written; | 1498 ++written; |
1556 } | 1499 } |
1557 | 1500 |
1558 if (written == 1) | 1501 if (written == 1) |
1559 ch_logn(channel, "written line %d to channel", (int)lnum - 1); | 1502 ch_log(channel, "written line %d to channel", (int)lnum - 1); |
1560 else if (written > 1) | 1503 else if (written > 1) |
1561 ch_logn(channel, "written %d lines to channel", written); | 1504 ch_log(channel, "written %d lines to channel", written); |
1562 if (lnum < buf->b_ml.ml_line_count) | 1505 if (lnum < buf->b_ml.ml_line_count) |
1563 ch_logn(channel, "Still %d more lines to write", | 1506 ch_log(channel, "Still %d more lines to write", |
1564 buf->b_ml.ml_line_count - lnum); | 1507 buf->b_ml.ml_line_count - lnum); |
1565 | 1508 |
1566 in_part->ch_buf_bot = lnum; | 1509 in_part->ch_buf_bot = lnum; |
1567 } | 1510 } |
1568 } | 1511 } |
1927 if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2) | 1870 if (listtv.v_type != VAR_LIST || listtv.vval.v_list->lv_len < 2) |
1928 { | 1871 { |
1929 if (listtv.v_type != VAR_LIST) | 1872 if (listtv.v_type != VAR_LIST) |
1930 ch_error(channel, "Did not receive a list, discarding"); | 1873 ch_error(channel, "Did not receive a list, discarding"); |
1931 else | 1874 else |
1932 ch_errorn(channel, "Expected list with two items, got %d", | 1875 ch_error(channel, "Expected list with two items, got %d", |
1933 listtv.vval.v_list->lv_len); | 1876 listtv.vval.v_list->lv_len); |
1934 clear_tv(&listtv); | 1877 clear_tv(&listtv); |
1935 } | 1878 } |
1936 else | 1879 else |
1937 { | 1880 { |
1970 | 1913 |
1971 if (chanpart->ch_wait_len < buflen) | 1914 if (chanpart->ch_wait_len < buflen) |
1972 { | 1915 { |
1973 /* First time encountering incomplete message or after receiving | 1916 /* First time encountering incomplete message or after receiving |
1974 * more (but still incomplete): set a deadline of 100 msec. */ | 1917 * more (but still incomplete): set a deadline of 100 msec. */ |
1975 ch_logn(channel, | 1918 ch_log(channel, |
1976 "Incomplete message (%d bytes) - wait 100 msec for more", | 1919 "Incomplete message (%d bytes) - wait 100 msec for more", |
1977 (int)buflen); | 1920 (int)buflen); |
1978 reader.js_used = 0; | 1921 reader.js_used = 0; |
1979 chanpart->ch_wait_len = buflen; | 1922 chanpart->ch_wait_len = buflen; |
1980 #ifdef WIN32 | 1923 #ifdef WIN32 |
2104 || tv->vval.v_number == 0 | 2047 || tv->vval.v_number == 0 |
2105 || tv->vval.v_number != channel->ch_part[part].ch_block_id)))) | 2048 || tv->vval.v_number != channel->ch_part[part].ch_block_id)))) |
2106 { | 2049 { |
2107 *rettv = item->jq_value; | 2050 *rettv = item->jq_value; |
2108 if (tv->v_type == VAR_NUMBER) | 2051 if (tv->v_type == VAR_NUMBER) |
2109 ch_logn(channel, "Getting JSON message %d", tv->vval.v_number); | 2052 ch_log(channel, "Getting JSON message %d", tv->vval.v_number); |
2110 remove_json_node(head, item); | 2053 remove_json_node(head, item); |
2111 return OK; | 2054 return OK; |
2112 } | 2055 } |
2113 item = item->jq_next; | 2056 item = item->jq_next; |
2114 } | 2057 } |
2202 if (STRCMP(cmd, "ex") == 0) | 2145 if (STRCMP(cmd, "ex") == 0) |
2203 { | 2146 { |
2204 int save_called_emsg = called_emsg; | 2147 int save_called_emsg = called_emsg; |
2205 | 2148 |
2206 called_emsg = FALSE; | 2149 called_emsg = FALSE; |
2207 ch_logs(channel, "Executing ex command '%s'", (char *)arg); | 2150 ch_log(channel, "Executing ex command '%s'", (char *)arg); |
2208 ++emsg_silent; | 2151 ++emsg_silent; |
2209 do_cmdline_cmd(arg); | 2152 do_cmdline_cmd(arg); |
2210 --emsg_silent; | 2153 --emsg_silent; |
2211 if (called_emsg) | 2154 if (called_emsg) |
2212 ch_logs(channel, "Ex command error: '%s'", | 2155 ch_log(channel, "Ex command error: '%s'", |
2213 (char *)get_vim_var_str(VV_ERRMSG)); | 2156 (char *)get_vim_var_str(VV_ERRMSG)); |
2214 called_emsg = save_called_emsg; | 2157 called_emsg = save_called_emsg; |
2215 } | 2158 } |
2216 else if (STRCMP(cmd, "normal") == 0) | 2159 else if (STRCMP(cmd, "normal") == 0) |
2217 { | 2160 { |
2218 exarg_T ea; | 2161 exarg_T ea; |
2219 | 2162 |
2220 ch_logs(channel, "Executing normal command '%s'", (char *)arg); | 2163 ch_log(channel, "Executing normal command '%s'", (char *)arg); |
2221 ea.arg = arg; | 2164 ea.arg = arg; |
2222 ea.addr_count = 0; | 2165 ea.addr_count = 0; |
2223 ea.forceit = TRUE; /* no mapping */ | 2166 ea.forceit = TRUE; /* no mapping */ |
2224 ex_normal(&ea); | 2167 ex_normal(&ea); |
2225 } | 2168 } |
2268 | 2211 |
2269 /* Don't pollute the display with errors. */ | 2212 /* Don't pollute the display with errors. */ |
2270 ++emsg_skip; | 2213 ++emsg_skip; |
2271 if (!is_call) | 2214 if (!is_call) |
2272 { | 2215 { |
2273 ch_logs(channel, "Evaluating expression '%s'", (char *)arg); | 2216 ch_log(channel, "Evaluating expression '%s'", (char *)arg); |
2274 tv = eval_expr(arg, NULL); | 2217 tv = eval_expr(arg, NULL); |
2275 } | 2218 } |
2276 else | 2219 else |
2277 { | 2220 { |
2278 ch_logs(channel, "Calling '%s'", (char *)arg); | 2221 ch_log(channel, "Calling '%s'", (char *)arg); |
2279 if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK) | 2222 if (func_call(arg, &argv[2], NULL, NULL, &res_tv) == OK) |
2280 tv = &res_tv; | 2223 tv = &res_tv; |
2281 } | 2224 } |
2282 | 2225 |
2283 if (argv[id_idx].v_type == VAR_NUMBER) | 2226 if (argv[id_idx].v_type == VAR_NUMBER) |
2310 free_tv(tv); | 2253 free_tv(tv); |
2311 } | 2254 } |
2312 } | 2255 } |
2313 else if (p_verbose > 2) | 2256 else if (p_verbose > 2) |
2314 { | 2257 { |
2315 ch_errors(channel, "Received unknown command: %s", (char *)cmd); | 2258 ch_error(channel, "Received unknown command: %s", (char *)cmd); |
2316 EMSG2(_("E905: received unknown command: %s"), cmd); | 2259 EMSG2(_("E905: received unknown command: %s"), cmd); |
2317 } | 2260 } |
2318 } | 2261 } |
2319 | 2262 |
2320 /* | 2263 /* |
2326 channel_T *channel, | 2269 channel_T *channel, |
2327 cbq_T *cbhead, | 2270 cbq_T *cbhead, |
2328 cbq_T *item, | 2271 cbq_T *item, |
2329 typval_T *argv) | 2272 typval_T *argv) |
2330 { | 2273 { |
2331 ch_logs(channel, "Invoking one-time callback %s", | 2274 ch_log(channel, "Invoking one-time callback %s", |
2332 (char *)item->cq_callback); | 2275 (char *)item->cq_callback); |
2333 /* Remove the item from the list first, if the callback | 2276 /* Remove the item from the list first, if the callback |
2334 * invokes ch_close() the list will be cleared. */ | 2277 * invokes ch_close() the list will be cleared. */ |
2335 remove_cb_node(cbhead, item); | 2278 remove_cb_node(cbhead, item); |
2336 invoke_callback(channel, item->cq_callback, item->cq_partial, argv); | 2279 invoke_callback(channel, item->cq_callback, item->cq_partial, argv); |
2365 --lnum; | 2308 --lnum; |
2366 buffer->b_write_to_channel = FALSE; | 2309 buffer->b_write_to_channel = FALSE; |
2367 } | 2310 } |
2368 | 2311 |
2369 /* Append to the buffer */ | 2312 /* Append to the buffer */ |
2370 ch_logn(channel, "appending line %d to buffer", (int)lnum + 1 - empty); | 2313 ch_log(channel, "appending line %d to buffer", (int)lnum + 1 - empty); |
2371 | 2314 |
2372 buffer->b_p_ma = TRUE; | 2315 buffer->b_p_ma = TRUE; |
2373 curbuf = buffer; | 2316 curbuf = buffer; |
2374 curwin->w_buffer = curbuf; | 2317 curwin->w_buffer = curbuf; |
2375 u_sync(TRUE); | 2318 u_sync(TRUE); |
2440 { | 2383 { |
2441 char_u *msg; | 2384 char_u *msg; |
2442 | 2385 |
2443 while ((msg = channel_get(channel, part)) != NULL) | 2386 while ((msg = channel_get(channel, part)) != NULL) |
2444 { | 2387 { |
2445 ch_logs(channel, "Dropping message '%s'", (char *)msg); | 2388 ch_log(channel, "Dropping message '%s'", (char *)msg); |
2446 vim_free(msg); | 2389 vim_free(msg); |
2447 } | 2390 } |
2448 } | 2391 } |
2449 | 2392 |
2450 /* | 2393 /* |
2495 buffer = ch_part->ch_bufref.br_buf; | 2438 buffer = ch_part->ch_bufref.br_buf; |
2496 if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref) | 2439 if (buffer != NULL && (!bufref_valid(&ch_part->ch_bufref) |
2497 || buffer->b_ml.ml_mfp == NULL)) | 2440 || buffer->b_ml.ml_mfp == NULL)) |
2498 { | 2441 { |
2499 /* buffer was wiped out or unloaded */ | 2442 /* buffer was wiped out or unloaded */ |
2500 ch_logs(channel, "%s buffer has been wiped out", part_names[part]); | 2443 ch_log(channel, "%s buffer has been wiped out", part_names[part]); |
2501 ch_part->ch_bufref.br_buf = NULL; | 2444 ch_part->ch_bufref.br_buf = NULL; |
2502 buffer = NULL; | 2445 buffer = NULL; |
2503 } | 2446 } |
2504 | 2447 |
2505 if (ch_mode == MODE_JSON || ch_mode == MODE_JS) | 2448 if (ch_mode == MODE_JSON || ch_mode == MODE_JS) |
2649 /* message must be read with ch_read() */ | 2592 /* message must be read with ch_read() */ |
2650 channel_push_json(channel, part, listtv); | 2593 channel_push_json(channel, part, listtv); |
2651 listtv = NULL; | 2594 listtv = NULL; |
2652 } | 2595 } |
2653 else | 2596 else |
2654 ch_logn(channel, "Dropping message %d without callback", | 2597 ch_log(channel, "Dropping message %d without callback", |
2655 seq_nr); | 2598 seq_nr); |
2656 } | 2599 } |
2657 } | 2600 } |
2658 else if (callback != NULL || buffer != NULL) | 2601 else if (callback != NULL || buffer != NULL) |
2659 { | 2602 { |
2678 if (cbitem != NULL) | 2621 if (cbitem != NULL) |
2679 invoke_one_time_callback(channel, cbhead, cbitem, argv); | 2622 invoke_one_time_callback(channel, cbhead, cbitem, argv); |
2680 else | 2623 else |
2681 { | 2624 { |
2682 /* invoke the channel callback */ | 2625 /* invoke the channel callback */ |
2683 ch_logs(channel, "Invoking channel callback %s", | 2626 ch_log(channel, "Invoking channel callback %s", |
2684 (char *)callback); | 2627 (char *)callback); |
2685 invoke_callback(channel, callback, partial, argv); | 2628 invoke_callback(channel, callback, partial, argv); |
2686 } | 2629 } |
2687 } | 2630 } |
2688 } | 2631 } |
2689 else | 2632 else |
2690 ch_logn(channel, "Dropping message %d", seq_nr); | 2633 ch_log(channel, "Dropping message %d", seq_nr); |
2691 | 2634 |
2692 if (listtv != NULL) | 2635 if (listtv != NULL) |
2693 free_tv(listtv); | 2636 free_tv(listtv); |
2694 vim_free(msg); | 2637 vim_free(msg); |
2695 | 2638 |
2886 ; | 2829 ; |
2887 | 2830 |
2888 /* Invoke the close callback, if still set. */ | 2831 /* Invoke the close callback, if still set. */ |
2889 if (channel->ch_close_cb != NULL) | 2832 if (channel->ch_close_cb != NULL) |
2890 { | 2833 { |
2891 ch_logs(channel, "Invoking close callback %s", | 2834 ch_log(channel, "Invoking close callback %s", |
2892 (char *)channel->ch_close_cb); | 2835 (char *)channel->ch_close_cb); |
2893 argv[0].v_type = VAR_CHANNEL; | 2836 argv[0].v_type = VAR_CHANNEL; |
2894 argv[0].vval.v_channel = channel; | 2837 argv[0].vval.v_channel = channel; |
2895 call_func(channel->ch_close_cb, (int)STRLEN(channel->ch_close_cb), | 2838 call_func(channel->ch_close_cb, (int)STRLEN(channel->ch_close_cb), |
2896 &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE, | 2839 &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE, |
3072 */ | 3015 */ |
3073 static channel_wait_result | 3016 static channel_wait_result |
3074 channel_wait(channel_T *channel, sock_T fd, int timeout) | 3017 channel_wait(channel_T *channel, sock_T fd, int timeout) |
3075 { | 3018 { |
3076 if (timeout > 0) | 3019 if (timeout > 0) |
3077 ch_logn(channel, "Waiting for up to %d msec", timeout); | 3020 ch_log(channel, "Waiting for up to %d msec", timeout); |
3078 | 3021 |
3079 # ifdef WIN32 | 3022 # ifdef WIN32 |
3080 if (fd != channel->CH_SOCK_FD) | 3023 if (fd != channel->CH_SOCK_FD) |
3081 { | 3024 { |
3082 DWORD nread; | 3025 DWORD nread; |
3173 | 3116 |
3174 static void | 3117 static void |
3175 ch_close_part_on_error( | 3118 ch_close_part_on_error( |
3176 channel_T *channel, ch_part_T part, int is_err, char *func) | 3119 channel_T *channel, ch_part_T part, int is_err, char *func) |
3177 { | 3120 { |
3178 char msgbuf[80]; | 3121 char msg[] = "%s(): Read %s from ch_part[%d], closing"; |
3179 | |
3180 vim_snprintf(msgbuf, sizeof(msgbuf), | |
3181 "%%s(): Read %s from ch_part[%d], closing", | |
3182 (is_err ? "error" : "EOF"), part); | |
3183 | 3122 |
3184 if (is_err) | 3123 if (is_err) |
3185 /* Do not call emsg(), most likely the other end just exited. */ | 3124 /* Do not call emsg(), most likely the other end just exited. */ |
3186 ch_errors(channel, msgbuf, func); | 3125 ch_error(channel, msg, func, "error", part); |
3187 else | 3126 else |
3188 ch_logs(channel, msgbuf, func); | 3127 ch_log(channel, msg, func, "EOF", part); |
3189 | 3128 |
3190 /* Queue a "DETACH" netbeans message in the command queue in order to | 3129 /* Queue a "DETACH" netbeans message in the command queue in order to |
3191 * terminate the netbeans session later. Do not end the session here | 3130 * terminate the netbeans session later. Do not end the session here |
3192 * directly as we may be running in the context of a call to | 3131 * directly as we may be running in the context of a call to |
3193 * netbeans_parse_messages(): | 3132 * netbeans_parse_messages(): |
3236 int use_socket = FALSE; | 3175 int use_socket = FALSE; |
3237 | 3176 |
3238 fd = channel->ch_part[part].ch_fd; | 3177 fd = channel->ch_part[part].ch_fd; |
3239 if (fd == INVALID_FD) | 3178 if (fd == INVALID_FD) |
3240 { | 3179 { |
3241 ch_errors(channel, "channel_read() called while %s part is closed", | 3180 ch_error(channel, "channel_read() called while %s part is closed", |
3242 part_names[part]); | 3181 part_names[part]); |
3243 return; | 3182 return; |
3244 } | 3183 } |
3245 use_socket = fd == channel->CH_SOCK_FD; | 3184 use_socket = fd == channel->CH_SOCK_FD; |
3246 | 3185 |
3298 ch_mode_T mode = channel->ch_part[part].ch_mode; | 3237 ch_mode_T mode = channel->ch_part[part].ch_mode; |
3299 sock_T fd = channel->ch_part[part].ch_fd; | 3238 sock_T fd = channel->ch_part[part].ch_fd; |
3300 char_u *nl; | 3239 char_u *nl; |
3301 readq_T *node; | 3240 readq_T *node; |
3302 | 3241 |
3303 ch_logsn(channel, "Blocking %s read, timeout: %d msec", | 3242 ch_log(channel, "Blocking %s read, timeout: %d msec", |
3304 mode == MODE_RAW ? "RAW" : "NL", timeout); | 3243 mode == MODE_RAW ? "RAW" : "NL", timeout); |
3305 | 3244 |
3306 while (TRUE) | 3245 while (TRUE) |
3307 { | 3246 { |
3308 node = channel_peek(channel, part); | 3247 node = channel_peek(channel, part); |
3357 msg = vim_strnsave(buf, (int)(nl - buf)); | 3296 msg = vim_strnsave(buf, (int)(nl - buf)); |
3358 channel_consume(channel, part, (int)(nl - buf) + 1); | 3297 channel_consume(channel, part, (int)(nl - buf) + 1); |
3359 } | 3298 } |
3360 } | 3299 } |
3361 if (log_fd != NULL) | 3300 if (log_fd != NULL) |
3362 ch_logn(channel, "Returning %d bytes", (int)STRLEN(msg)); | 3301 ch_log(channel, "Returning %d bytes", (int)STRLEN(msg)); |
3363 return msg; | 3302 return msg; |
3364 } | 3303 } |
3365 | 3304 |
3366 /* | 3305 /* |
3367 * Read one JSON message with ID "id" from "channel"/"part" and store the | 3306 * Read one JSON message with ID "id" from "channel"/"part" and store the |
3589 fd = channel->ch_part[part].ch_fd; | 3528 fd = channel->ch_part[part].ch_fd; |
3590 if (fd == INVALID_FD) | 3529 if (fd == INVALID_FD) |
3591 { | 3530 { |
3592 if (!channel->ch_error && fun != NULL) | 3531 if (!channel->ch_error && fun != NULL) |
3593 { | 3532 { |
3594 ch_errors(channel, "%s(): write while not connected", fun); | 3533 ch_error(channel, "%s(): write while not connected", fun); |
3595 EMSG2(_("E630: %s(): write while not connected"), fun); | 3534 EMSG2(_("E630: %s(): write while not connected"), fun); |
3596 } | 3535 } |
3597 channel->ch_error = TRUE; | 3536 channel->ch_error = TRUE; |
3598 return FAIL; | 3537 return FAIL; |
3599 } | 3538 } |
3614 res = fd_write(fd, (char *)buf, len); | 3553 res = fd_write(fd, (char *)buf, len); |
3615 if (res != len) | 3554 if (res != len) |
3616 { | 3555 { |
3617 if (!channel->ch_error && fun != NULL) | 3556 if (!channel->ch_error && fun != NULL) |
3618 { | 3557 { |
3619 ch_errors(channel, "%s(): write failed", fun); | 3558 ch_error(channel, "%s(): write failed", fun); |
3620 EMSG2(_("E631: %s(): write failed"), fun); | 3559 EMSG2(_("E631: %s(): write failed"), fun); |
3621 } | 3560 } |
3622 channel->ch_error = TRUE; | 3561 channel->ch_error = TRUE; |
3623 return FAIL; | 3562 return FAIL; |
3624 } | 3563 } |
5087 { | 5026 { |
5088 if (i > 0) | 5027 if (i > 0) |
5089 ga_concat(&ga, (char_u *)" "); | 5028 ga_concat(&ga, (char_u *)" "); |
5090 ga_concat(&ga, (char_u *)argv[i]); | 5029 ga_concat(&ga, (char_u *)argv[i]); |
5091 } | 5030 } |
5092 ch_logs(NULL, "Starting job: %s", (char *)ga.ga_data); | 5031 ch_log(NULL, "Starting job: %s", (char *)ga.ga_data); |
5093 ga_clear(&ga); | 5032 ga_clear(&ga); |
5094 } | 5033 } |
5095 mch_job_start(argv, job, &opt); | 5034 mch_job_start(argv, job, &opt); |
5096 #else | 5035 #else |
5097 ch_logs(NULL, "Starting job: %s", (char *)cmd); | 5036 ch_log(NULL, "Starting job: %s", (char *)cmd); |
5098 mch_job_start((char *)cmd, job, &opt); | 5037 mch_job_start((char *)cmd, job, &opt); |
5099 #endif | 5038 #endif |
5100 | 5039 |
5101 /* If the channel is reading from a buffer, write lines now. */ | 5040 /* If the channel is reading from a buffer, write lines now. */ |
5102 if (job->jv_channel != NULL) | 5041 if (job->jv_channel != NULL) |
5202 if (job->jv_status == JOB_ENDED) | 5141 if (job->jv_status == JOB_ENDED) |
5203 { | 5142 { |
5204 ch_log(job->jv_channel, "Job has already ended, job_stop() skipped"); | 5143 ch_log(job->jv_channel, "Job has already ended, job_stop() skipped"); |
5205 return 0; | 5144 return 0; |
5206 } | 5145 } |
5207 ch_logs(job->jv_channel, "Stopping job with '%s'", (char *)arg); | 5146 ch_log(job->jv_channel, "Stopping job with '%s'", (char *)arg); |
5208 if (mch_stop_job(job, arg) == FAIL) | 5147 if (mch_stop_job(job, arg) == FAIL) |
5209 return 0; | 5148 return 0; |
5210 | 5149 |
5211 /* Assume that only "kill" will kill the job. */ | 5150 /* Assume that only "kill" will kill the job. */ |
5212 if (job->jv_channel != NULL && STRCMP(arg, "kill") == 0) | 5151 if (job->jv_channel != NULL && STRCMP(arg, "kill") == 0) |