Fix bad event loop causing hangs in certain situations.
Always wait for ack (also with -e), otherwise the message could get lost. SVN revision: 31869
This commit is contained in:
parent
8f2289a107
commit
e860b36218
3
eesh/E.h
3
eesh/E.h
|
@ -44,7 +44,8 @@ typedef struct
|
|||
char *msg;
|
||||
} Client;
|
||||
|
||||
Window CommsSetup(void);
|
||||
void CommsInit(void);
|
||||
Window CommsSetup(Window win);
|
||||
Window CommsFindCommsWindow(void);
|
||||
void CommsSend(Client * c, const char *s);
|
||||
char *CommsGet(Client * c, XEvent * ev);
|
||||
|
|
35
eesh/comms.c
35
eesh/comms.c
|
@ -27,14 +27,19 @@
|
|||
static Window root_win;
|
||||
static Window my_win;
|
||||
|
||||
Window
|
||||
CommsSetup(void)
|
||||
void
|
||||
CommsInit(void)
|
||||
{
|
||||
char *str;
|
||||
XSetWindowAttributes attr;
|
||||
|
||||
str = getenv("ENL_WM_ROOT");
|
||||
root_win = (str) ? strtoul(str, NULL, 0) : DefaultRootWindow(disp);
|
||||
}
|
||||
|
||||
Window
|
||||
CommsSetup(Window win __UNUSED__)
|
||||
{
|
||||
XSetWindowAttributes attr;
|
||||
|
||||
attr.override_redirect = False;
|
||||
my_win = XCreateWindow(disp, root_win, -100, -100, 5, 5, 0, 0, InputOnly,
|
||||
|
@ -128,7 +133,7 @@ char *
|
|||
CommsGet(Client * c, XEvent * ev)
|
||||
{
|
||||
char s[13], s2[9], *msg;
|
||||
int i;
|
||||
unsigned int i;
|
||||
Window win;
|
||||
|
||||
if ((!ev) || (!c))
|
||||
|
@ -147,24 +152,14 @@ CommsGet(Client * c, XEvent * ev)
|
|||
|
||||
sscanf(s2, "%lx", &win);
|
||||
|
||||
if (c->msg)
|
||||
{
|
||||
/* append text to end of msg */
|
||||
c->msg = EREALLOC(char, c->msg, strlen(c->msg) + strlen(s) + 1);
|
||||
/* append text to end of msg */
|
||||
i = (c->msg) ? strlen(c->msg) : 0;
|
||||
c->msg = EREALLOC(char, c->msg, i + strlen(s) + 1);
|
||||
|
||||
if (!c->msg)
|
||||
return NULL;
|
||||
strcat(c->msg, s);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* new msg */
|
||||
c->msg = EMALLOC(char, strlen(s) + 1);
|
||||
if (!c->msg)
|
||||
return NULL;
|
||||
strcpy(c->msg + i, s);
|
||||
|
||||
if (!c->msg)
|
||||
return NULL;
|
||||
strcpy(c->msg, s);
|
||||
}
|
||||
if (strlen(s) < 12)
|
||||
{
|
||||
msg = c->msg;
|
||||
|
|
56
eesh/main.c
56
eesh/main.c
|
@ -21,7 +21,6 @@
|
|||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "E.h"
|
||||
|
||||
/* Global vars */
|
||||
|
@ -149,14 +148,15 @@ main(int argc, char **argv)
|
|||
exit(1);
|
||||
}
|
||||
|
||||
my_win = CommsSetup();
|
||||
CommsInit();
|
||||
comms_win = CommsFindCommsWindow();
|
||||
my_win = CommsSetup(comms_win);
|
||||
|
||||
e = ClientCreate(comms_win);
|
||||
me = ClientCreate(my_win);
|
||||
|
||||
CommsSend(e, "set clientname eesh");
|
||||
CommsSend(e, "set version 0.1");
|
||||
CommsSend(e, "set version 0.2");
|
||||
#if 0 /* Speed it up */
|
||||
CommsSend(e, "set author The Rasterman");
|
||||
CommsSend(e, "set email raster@rasterman.com");
|
||||
|
@ -187,8 +187,10 @@ main(int argc, char **argv)
|
|||
/* Non-interactive */
|
||||
CommsSend(e, command);
|
||||
XSync(disp, False);
|
||||
#if 0 /* No - Wait for ack */
|
||||
if (mode <= 0)
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -199,6 +201,28 @@ main(int argc, char **argv)
|
|||
|
||||
for (;;)
|
||||
{
|
||||
XSync(disp, False);
|
||||
while (XPending(disp))
|
||||
{
|
||||
XNextEvent(disp, &ev);
|
||||
switch (ev.type)
|
||||
{
|
||||
case ClientMessage:
|
||||
s = CommsGet(me, &ev);
|
||||
if (!s)
|
||||
break;
|
||||
if (*s)
|
||||
printf("%s", s);
|
||||
fflush(stdout);
|
||||
Efree(s);
|
||||
if (mode)
|
||||
goto done;
|
||||
break;
|
||||
case DestroyNotify:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
FD_ZERO(&fd);
|
||||
if (!command)
|
||||
FD_SET(0, &fd);
|
||||
|
@ -207,36 +231,10 @@ main(int argc, char **argv)
|
|||
if (select(ConnectionNumber(disp) + 1, &fd, NULL, NULL, NULL) < 0)
|
||||
break;
|
||||
|
||||
XSync(disp, False);
|
||||
|
||||
if (FD_ISSET(0, &fd))
|
||||
{
|
||||
stdin_read();
|
||||
}
|
||||
else if (FD_ISSET(ConnectionNumber(disp), &fd))
|
||||
{
|
||||
while (XPending(disp))
|
||||
{
|
||||
XNextEvent(disp, &ev);
|
||||
switch (ev.type)
|
||||
{
|
||||
case ClientMessage:
|
||||
s = CommsGet(me, &ev);
|
||||
if (!s)
|
||||
break;
|
||||
if (*s)
|
||||
printf("%s", s);
|
||||
fflush(stdout);
|
||||
Efree(s);
|
||||
if (mode)
|
||||
goto done;
|
||||
break;
|
||||
case DestroyNotify:
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
XSync(disp, False);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
|
Loading…
Reference in New Issue