1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Introduce an enum of the uxsel / select_result flags.

Those magic numbers 1,2,4 were getting annoying. Time to replace them
while I can still remember what they do.
This commit is contained in:
Simon Tatham 2019-02-07 18:13:56 +00:00
parent 9f0e0b02e3
commit 47202c4e16
10 changed files with 40 additions and 39 deletions

View File

@ -82,11 +82,11 @@ gboolean fd_input_func(GIOChannel *source, GIOCondition condition,
* marker.
*/
if (condition & G_IO_PRI)
select_result(sourcefd, 4);
select_result(sourcefd, SELECT_X);
if (condition & (G_IO_IN | G_IO_HUP))
select_result(sourcefd, 1);
select_result(sourcefd, SELECT_R);
if (condition & G_IO_OUT)
select_result(sourcefd, 2);
select_result(sourcefd, SELECT_W);
return true;
}
@ -94,11 +94,11 @@ gboolean fd_input_func(GIOChannel *source, GIOCondition condition,
void fd_input_func(gpointer data, gint sourcefd, GdkInputCondition condition)
{
if (condition & GDK_INPUT_EXCEPTION)
select_result(sourcefd, 4);
select_result(sourcefd, SELECT_X);
if (condition & GDK_INPUT_READ)
select_result(sourcefd, 1);
select_result(sourcefd, SELECT_R);
if (condition & GDK_INPUT_WRITE)
select_result(sourcefd, 2);
select_result(sourcefd, SELECT_W);
}
#endif

View File

@ -315,6 +315,7 @@ void uxsel_init(void);
typedef void (*uxsel_callback_fn)(int fd, int event);
void uxsel_set(int fd, int rwx, uxsel_callback_fn callback);
void uxsel_del(int fd);
enum { SELECT_R = 1, SELECT_W = 2, SELECT_X = 4 };
void select_result(int fd, int event);
int first_fd(int *state, int *rwx);
int next_fd(int *state, int *rwx);

View File

@ -104,7 +104,7 @@ static void agent_select_result(int fd, int event)
{
agent_pending_query *conn;
assert(event == 1); /* not selecting for anything but R */
assert(event == SELECT_R); /* not selecting for anything but R */
conn = find234(agent_pending_queries, &fd, agent_connfind);
if (!conn) {
@ -203,7 +203,7 @@ agent_pending_query *agent_query(
agent_pending_queries = newtree234(agent_conncmp);
add234(agent_pending_queries, conn);
uxsel_set(sock, 1, agent_select_result);
uxsel_set(sock, SELECT_R, agent_select_result);
return conn;
failure:

View File

@ -192,7 +192,7 @@ static int fdsocket_try_send(FdSocket *fds)
if (bufchain_size(&fds->pending_output_data) == 0)
uxsel_del(fds->outfd);
else
uxsel_set(fds->outfd, 2, fdsocket_select_result_output);
uxsel_set(fds->outfd, SELECT_W, fdsocket_select_result_output);
return sent;
}
@ -245,7 +245,7 @@ static void fdsocket_set_frozen(Socket *s, bool is_frozen)
if (is_frozen)
uxsel_del(fds->infd);
else
uxsel_set(fds->infd, 1, fdsocket_select_result_input);
uxsel_set(fds->infd, SELECT_R, fdsocket_select_result_input);
}
static const char *fdsocket_socket_error(Socket *s)
@ -349,7 +349,7 @@ Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug)
if (!fdsocket_by_infd)
fdsocket_by_infd = newtree234(fdsocket_infd_cmp);
add234(fdsocket_by_infd, fds);
uxsel_set(fds->infd, 1, fdsocket_select_result_input);
uxsel_set(fds->infd, SELECT_R, fdsocket_select_result_input);
}
if (fds->inerrfd >= 0) {
@ -357,7 +357,7 @@ Socket *make_fd_socket(int infd, int outfd, int inerrfd, Plug *plug)
if (!fdsocket_by_inerrfd)
fdsocket_by_inerrfd = newtree234(fdsocket_inerrfd_cmp);
add234(fdsocket_by_inerrfd, fds);
uxsel_set(fds->inerrfd, 1, fdsocket_select_result_input_error);
uxsel_set(fds->inerrfd, SELECT_R, fdsocket_select_result_input_error);
}
return &fds->sock;

View File

@ -1283,7 +1283,7 @@ static void net_select_result(int fd, int event)
noise_ultralight(NOISE_SOURCE_IOID, fd);
switch (event) {
case 4: /* exceptional */
case SELECT_X: /* exceptional */
if (!s->oobinline) {
/*
* On a non-oobinline socket, this indicates that we
@ -1320,7 +1320,7 @@ static void net_select_result(int fd, int event)
*/
s->oobpending = true;
break;
case 1: /* readable; also acceptance */
case SELECT_R: /* readable; also acceptance */
if (s->listener) {
/*
* On a listening socket, the readability event means a
@ -1400,7 +1400,7 @@ static void net_select_result(int fd, int event)
plug_receive(s->plug, atmark ? 0 : 1, buf, ret);
}
break;
case 2: /* writable */
case SELECT_W: /* writable */
if (!s->connected) {
/*
* select() reports a socket as _writable_ when an
@ -1559,14 +1559,14 @@ static void uxsel_tell(NetSocket *s)
int rwx = 0;
if (!s->pending_error) {
if (s->listener) {
rwx |= 1; /* read == accept */
rwx |= SELECT_R; /* read == accept */
} else {
if (!s->connected)
rwx |= 2; /* write == connect */
rwx |= SELECT_W; /* write == connect */
if (s->connected && !s->frozen && !s->incomingeof)
rwx |= 1 | 4; /* read, except */
rwx |= SELECT_R | SELECT_X;
if (bufchain_size(&s->output_data))
rwx |= 2; /* write */
rwx |= SELECT_W;
}
}
uxsel_set(s->s, rwx, net_select_result);

View File

@ -958,11 +958,11 @@ void run_agent(void)
* past the urgent marker.
*/
if (FD_ISSET(fd, &xset))
select_result(fd, 4);
select_result(fd, SELECT_X);
if (FD_ISSET(fd, &rset))
select_result(fd, 1);
select_result(fd, SELECT_R);
if (FD_ISSET(fd, &wset))
select_result(fd, 2);
select_result(fd, SELECT_W);
}
if (signalpipe[0] >= 0 && FD_ISSET(signalpipe[0], &rset)) {

View File

@ -974,11 +974,11 @@ int main(int argc, char **argv)
* past the urgent marker.
*/
if (FD_ISSET(fd, &xset))
select_result(fd, 4);
select_result(fd, SELECT_X);
if (FD_ISSET(fd, &rset))
select_result(fd, 1);
select_result(fd, SELECT_R);
if (FD_ISSET(fd, &wset))
select_result(fd, 2);
select_result(fd, SELECT_W);
}
if (FD_ISSET(signalpipe[0], &rset)) {

View File

@ -629,7 +629,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
finished = true;
}
} else {
if (event == 1) {
if (event == SELECT_R) {
bool is_stdout = (fd == pty->master_o);
ret = read(fd, buf, sizeof(buf));
@ -679,7 +679,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status)
} else if (ret > 0) {
seat_output(pty->seat, !is_stdout, buf, ret);
}
} else if (event == 2) {
} else if (event == SELECT_W) {
/*
* Attempt to send data down the pty.
*/
@ -781,10 +781,10 @@ static void pty_uxsel_setup_fd(Pty *pty, int fd)
/* read from standard output and standard error pipes */
if (pty->master_o == fd || pty->master_e == fd)
rwx |= 1;
rwx |= SELECT_R;
/* write to standard input pipe if we have any data */
if (pty->master_i == fd && bufchain_size(&pty->output_data))
rwx |= 2;
rwx |= SELECT_W;
uxsel_set(fd, rwx, pty_select_result);
}
@ -794,9 +794,9 @@ static void pty_uxsel_setup(Pty *pty)
/*
* We potentially have three separate fds here, but on the other
* hand, some of them might be the same (if they're a pty master).
* So we can't just call uxsel_set(master_o, 1) and then
* uxsel_set(master_i, 2), without the latter potentially undoing
* the work of the former if master_o == master_i.
* So we can't just call uxsel_set(master_o, SELECT_R) and then
* uxsel_set(master_i, SELECT_W), without the latter potentially
* undoing the work of the former if master_o == master_i.
*
* Instead, here we call a single uxsel on each one of these fds
* (if it exists at all), and for each one, check it against all
@ -811,7 +811,7 @@ static void pty_uxsel_setup(Pty *pty)
* backend instances, but it's simplest just to call it every
* time; uxsel won't mind.
*/
uxsel_set(pty_signal_pipe[0], 1, pty_select_result);
uxsel_set(pty_signal_pipe[0], SELECT_R, pty_select_result);
}
static void copy_ttymodes_into_termios(

View File

@ -639,11 +639,11 @@ int main(int argc, char **argv)
* past the urgent marker.
*/
if (FD_ISSET(fd, &xset))
select_result(fd, 4);
select_result(fd, SELECT_X);
if (FD_ISSET(fd, &rset))
select_result(fd, 1);
select_result(fd, SELECT_R);
if (FD_ISSET(fd, &wset))
select_result(fd, 2);
select_result(fd, SELECT_W);
}
run_toplevel_callbacks();

View File

@ -543,11 +543,11 @@ static int ssh_sftp_do_select(bool include_stdin, bool no_fds_ok)
* past the urgent marker.
*/
if (FD_ISSET(fd, &xset))
select_result(fd, 4);
select_result(fd, SELECT_X);
if (FD_ISSET(fd, &rset))
select_result(fd, 1);
select_result(fd, SELECT_R);
if (FD_ISSET(fd, &wset))
select_result(fd, 2);
select_result(fd, SELECT_W);
}
sfree(fdlist);