| Revision 4380,
1.4 KB
checked in by sam, 3 years ago
(diff) |
|
Implement bidirectional communication in mini-neercs.
|
-
Property svn:keywords set to
Id
|
| Line | |
|---|
| 1 | /* |
|---|
| 2 | * neercs console-based window manager |
|---|
| 3 | * Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net> |
|---|
| 4 | * 2008-2010 Jean-Yves Lamoureux <jylam@lnxscene.org> |
|---|
| 5 | * 2008-2010 Pascal Terjan <pterjan@linuxfr.org> |
|---|
| 6 | * All Rights Reserved |
|---|
| 7 | * |
|---|
| 8 | * This program is free software. It comes without any warranty, to |
|---|
| 9 | * the extent permitted by applicable law. You can redistribute it |
|---|
| 10 | * and/or modify it under the terms of the Do What The Fuck You Want |
|---|
| 11 | * To Public License, Version 2, as published by Sam Hocevar. See |
|---|
| 12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 13 | */ |
|---|
| 14 | |
|---|
| 15 | #if defined HAVE_CONFIG_H |
|---|
| 16 | # include "config.h" |
|---|
| 17 | #endif |
|---|
| 18 | |
|---|
| 19 | #include <stdio.h> /* BUFSIZ */ |
|---|
| 20 | #include <string.h> /* strncmp() */ |
|---|
| 21 | |
|---|
| 22 | #include "mini-neercs.h" |
|---|
| 23 | #include "mini-socket.h" |
|---|
| 24 | |
|---|
| 25 | static nrx_socket_t *insock, *outsock; |
|---|
| 26 | |
|---|
| 27 | void server_init(void) |
|---|
| 28 | { |
|---|
| 29 | insock = socket_open("/tmp/neercs.sock", 1); |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | int server_step(void) |
|---|
| 33 | { |
|---|
| 34 | char buf[BUFSIZ]; |
|---|
| 35 | ssize_t bytes; |
|---|
| 36 | int ret; |
|---|
| 37 | |
|---|
| 38 | ret = socket_select(insock, 1000); |
|---|
| 39 | if (ret <= 0) |
|---|
| 40 | return 1; |
|---|
| 41 | |
|---|
| 42 | bytes = socket_read(insock, buf, BUFSIZ); |
|---|
| 43 | if (bytes <= 0) |
|---|
| 44 | return 1; |
|---|
| 45 | |
|---|
| 46 | /* Parse message */ |
|---|
| 47 | if (!strncmp(buf, "CONNECT ", strlen("CONNECT "))) |
|---|
| 48 | { |
|---|
| 49 | outsock = socket_open(buf + strlen("CONNECT "), 0); |
|---|
| 50 | socket_puts(outsock, "OK"); |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | return 1; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | void server_fini(void) |
|---|
| 57 | { |
|---|
| 58 | if (insock) |
|---|
| 59 | socket_close(insock); |
|---|
| 60 | if (outsock) |
|---|
| 61 | socket_close(outsock); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.