[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r29898 - msh/src
From: |
gnunet |
Subject: |
[GNUnet-SVN] r29898 - msh/src |
Date: |
Sun, 6 Oct 2013 20:24:55 +0200 |
Author: harsha
Date: 2013-10-06 20:24:55 +0200 (Sun, 06 Oct 2013)
New Revision: 29898
Modified:
msh/src/Makefile.am
msh/src/msh_waiter.c
msh/src/mtypes.h
msh/src/ttymodes.c
Log:
- msh waiter
Modified: msh/src/Makefile.am
===================================================================
--- msh/src/Makefile.am 2013-10-06 14:10:19 UTC (rev 29897)
+++ msh/src/Makefile.am 2013-10-06 18:24:55 UTC (rev 29898)
@@ -1,4 +1,4 @@
-bin_PROGRAMS = mping mshd msh test-pty
+bin_PROGRAMS = mping mshd msh test-pty msh-waiter
mping_SOURCES = mping.c
@@ -33,3 +33,6 @@
test_pty_SOURCES = test_pty.c
test_pty_LDADD = -lgnunetutil
+
+msh_waiter_SOURCES = msh_waiter.c mtypes.h ttymodes.h ttymodes.c
+msh_waiter_LDADD = -lgnunetutil
\ No newline at end of file
Modified: msh/src/msh_waiter.c
===================================================================
--- msh/src/msh_waiter.c 2013-10-06 14:10:19 UTC (rev 29897)
+++ msh/src/msh_waiter.c 2013-10-06 18:24:55 UTC (rev 29898)
@@ -1,5 +1,6 @@
#include "common.h"
#include <gnunet/gnunet_util_lib.h>
+#include "mtypes.h"
#include <termios.h>
#define LOG(kind,...) \
@@ -10,26 +11,37 @@
#define LOG_ERROR(...) LOG(GNUNET_ERROR_TYPE_ERROR, __VA_ARGS__)
#define TIMEOUT(secs) \
- GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, secs);
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, secs)
#define DEFAULT_TIMEOUT TIMEOUT(30)
#define PROG_NAME "msh-waiter"
-unsigned int port;
+static unsigned int port;
static struct GNUNET_CONFIGURATION_Handle *cfg;
static struct GNUNET_NETWORK_Handle *lsock;
-static struct GNUNET_NETWORK_Handle *conn;
+static struct GNUNET_CONNECTION_Handle *conn;
static struct GNUNET_MessageHeader *msg;
static struct GNUNET_CONNECTION_TransmitHandle *handle_tx;
+static struct GNUNET_DISK_FileHandle *fh_stdin;
+
+static struct termios saved_tio;
+
+static int in_raw_mode;
+
static int in_receive;
+#define BUF_SIZE 512
+static char in_buf[BUF_SIZE];
+
+static ssize_t size_in_buf;
+
static void
do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -46,19 +58,33 @@
if (NULL != cfg)
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free_non_null (msg);
+ if (!in_raw_mode)
+ return;
+ if (tcsetattr(fileno(stdin), TCSADRAIN, &saved_tio) == -1)
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "tcsetattr");
+ LOG_ERROR ("Failed to set terminal back from raw mode. "
+ "The terminal may behave wierdly\n");
+ }
+ if (NULL != fh_stdin)
+ GNUNET_DISK_file_close (fh_stdin);
}
+
+/**
+ * Set the terminal into raw mode
+ */
void
enter_raw_mode(int quiet)
{
struct termios tio;
if (tcgetattr(fileno(stdin), &tio) == -1) {
- if (!quiet)
- perror("tcgetattr");
- return;
+ if (!quiet)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "tcgetattr");
+ return;
}
- _saved_tio = tio;
+ saved_tio = tio;
tio.c_iflag |= IGNPAR;
tio.c_iflag &= ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXANY | IXOFF);
#ifdef IUCLC
@@ -72,10 +98,10 @@
tio.c_cc[VMIN] = 1;
tio.c_cc[VTIME] = 0;
if (tcsetattr(fileno(stdin), TCSADRAIN, &tio) == -1) {
- if (!quiet)
- perror("tcsetattr");
+ if (!quiet)
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "tcsetattr");
} else
- _in_raw_mode = 1;
+ in_raw_mode = 1;
}
@@ -95,11 +121,31 @@
receive (void *cls, const void *buf, size_t available,
const struct sockaddr * addr, socklen_t addrlen, int errCode)
{
- GNUNET_break (0);
+ in_receive = GNUNET_NO;
+ if (0 == available)
+ goto err_ret;
+ if (available != fwrite (buf, 1, available, stdout))
+ {
+ LOG_ERROR ("Error writing to stdout\n");
+ goto err_ret;
+ }
+ GNUNET_CONNECTION_receive (conn, GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ GNUNET_TIME_UNIT_FOREVER_REL, &receive, NULL);
+ return;
+
+ err_ret:
+ GNUNET_SCHEDULER_shutdown ();
}
/**
+ * Task to read from stdin
+ */
+static void
+read_stdin (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+
+
+/**
* Transmit the global msg
*
* @param cls closure
@@ -108,8 +154,53 @@
* @return number of bytes written to buf
*/
static size_t
-do_tx (void *cls, size_t size, void *buf)
+tx_stdin (void *cls, size_t size, void *buf)
{
+ handle_tx = NULL;
+ if ((NULL == buf) || (0 == size))
+ {
+ LOG_ERROR ("Failure in connectivity\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ (void) memcpy (buf, in_buf, size_in_buf);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_stdin,
+ &read_stdin, NULL);
+}
+
+
+/**
+ * Task to read from stdin
+ */
+static void
+read_stdin (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
+ return;
+ size_in_buf = GNUNET_DISK_file_read (fh_stdin, in_buf, BUF_SIZE);
+ if (GNUNET_SYSERR == size_in_buf)
+ {
+ LOG_ERROR ("Read error\n");
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ handle_tx = GNUNET_CONNECTION_notify_transmit_ready (conn, size_in_buf,
+ DEFAULT_TIMEOUT,
+ &tx_stdin, NULL);
+}
+
+
+/**
+ * Transmit the global msg
+ *
+ * @param cls closure
+ * @param size number of bytes available in buf
+ * @param buf where the callee should write the message
+ * @return number of bytes written to buf
+ */
+static size_t
+tx_pty_mode (void *cls, size_t size, void *buf)
+{
size_t nb;
handle_tx = NULL;
@@ -125,13 +216,19 @@
(void) memcpy (buf, msg, nb);
GNUNET_free (msg);
msg = NULL;
- if (!in_receive)
- GNUNET_CONNECTION_receive (conn, GNUNET_SERVER_MAX_MESSAGE_SIZE,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &receive, NULL);
+ GNUNET_CONNECTION_receive (conn, GNUNET_SERVER_MAX_MESSAGE_SIZE,
+ GNUNET_TIME_UNIT_FOREVER_REL, &receive, NULL);
+ in_receive = GNUNET_YES;
+ fh_stdin = GNUNET_DISK_get_handle_from_native (stdin);
+ GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, fh_stdin,
+ &read_stdin, NULL);
+ return nb;
}
+/**
+ * Accept a connection on listen socket
+ */
static void
accept_lsock (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
@@ -144,6 +241,8 @@
unsigned int count;
int baud;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+ return;
conn = GNUNET_CONNECTION_create_from_accept (NULL, NULL, lsock);
GNUNET_NETWORK_socket_close (lsock);
lsock = NULL;
@@ -168,7 +267,7 @@
#undef TTYMODE
size = sizeof (struct MSH_MSG_PtyMode) +
- (sizeof (uint16_t) * 2) + ((NULL != cp) ? strlen(cp) : 0) + 1;
+ (sizeof (uint16_t) * 2 * count) + ((NULL != cp) ? (strlen(cp) + 1) : 0);
if (-1 == tcgetattr (0, &tio))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "tcgetattr");
@@ -190,7 +289,7 @@
ts++;
#define TTYCHAR(NAME,OP) \
*(ts++) = htons (OP); \
- *(ts++) = htons (tio.cc[NAME]);
+ *(ts++) = htons (tio.c_cc[NAME]);
#define TTYMODE(NAME, FIELD, OP) \
*(ts++) = htons (OP); \
@@ -201,10 +300,10 @@
if (NULL != cp)
(void) memcpy ((void *)ts, cp, strlen (cp));
- enter_raw_mode (1)
-
- hanlde_tx = GNUNET_CONNECTION_notify_transmit_ready (conn, size,
DEFAULT_TIMEOUT,
- &do_tx, NULL);
+ enter_raw_mode (1);
+ msg = &tmsg->header;
+ handle_tx = GNUNET_CONNECTION_notify_transmit_ready (conn, size,
DEFAULT_TIMEOUT,
+ &tx_pty_mode, NULL);
if (NULL == handle_tx)
{
LOG_ERROR ("Failed to transmit PTY mode\n");
@@ -234,9 +333,10 @@
cfg = GNUNET_CONFIGURATION_dup (c);
lsock = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
memset (&laddr, 0, sizeof (laddr));
- laddr.sin_addr = INADDR_ANY;
+ laddr.sin_addr.s_addr = INADDR_ANY;
laddr.sin_port = htons (port);
- ret = GNUNET_NETWORK_socket_bind (lsock, &laddr, sizeof (laddr), 0);
+ ret = GNUNET_NETWORK_socket_bind (lsock, (const struct sockaddr *) &laddr,
+ sizeof (laddr), 0);
if (GNUNET_SYSERR == ret)
goto err_ret;
ret = GNUNET_NETWORK_socket_listen (lsock, 1);
@@ -244,19 +344,22 @@
goto err_ret;
GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- lsock, accept_lsock, NULL);
+ lsock, &accept_lsock, NULL);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&do_shutdown, NULL);
+ return;
+
err_ret:
GNUNET_NETWORK_socket_close (lsock);
GNUNET_CONFIGURATION_destroy (cfg);
return;
}
+
int main (int argc, char * const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'l', "listen", NULL, gettext_noop ("listen port"),
+ {'p', "port", NULL, gettext_noop ("listen port"),
GNUNET_YES, &GNUNET_GETOPT_set_uint, &port},
GNUNET_GETOPT_OPTION_END
};
Modified: msh/src/mtypes.h
===================================================================
--- msh/src/mtypes.h 2013-10-06 14:10:19 UTC (rev 29897)
+++ msh/src/mtypes.h 2013-10-06 18:24:55 UTC (rev 29898)
@@ -133,6 +133,12 @@
#define MSH_MTYPE_EXEC_BEGIN 208
+/***********************/
+/* MSH waiter messages */
+/***********************/
+
+#define MSH_MTYPE_PTY_MODE 300
+
/**
* Message for sending a remote command and its arguments to MSHD
*/
Modified: msh/src/ttymodes.c
===================================================================
--- msh/src/ttymodes.c 2013-10-06 14:10:19 UTC (rev 29897)
+++ msh/src/ttymodes.c 2013-10-06 18:24:55 UTC (rev 29898)
@@ -61,7 +61,7 @@
* Converts POSIX speed_t to a baud rate. The values of the
* constants for speed_t are not themselves portable.
*/
-static int
+int
speed_to_baud(speed_t speed)
{
switch (speed) {
@@ -150,7 +150,7 @@
/*
* Converts a numeric baud rate to a POSIX speed_t.
*/
-static speed_t
+speed_t
baud_to_speed(int baud)
{
switch (baud) {
@@ -262,7 +262,7 @@
return c;
}
-#ifdef 0 /* begin code ignore */
+#if 0 /* begin code ignore */
/*
* Encodes terminal modes for the terminal referenced by fd
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r29898 - msh/src,
gnunet <=