#include <stdlib.h>
#include <string.h>
-#include "debug.h"
-
#include "morep.h"
+#include "verbose.h"
char *progname = NULL;
int stop = 0;
+DECLARE_VERBOSE_LEVEL (morep, INFO);
+
void sig_handler (int sig)
{
switch (sig) {
}
}
-int morep_server (char *url) {
+int server (char *url)
{
VERBOSE (morep, TRACE, PRINTF ("morep_server\n"));
- int fd = MOREP_Connect (url);
-
- VERBOSE (morep, INFO, PRINTF ("server started at '%s'\n", url));
-
- int morep = MOREP_Connect (local_address, remote_address);
+ int morep = MOREP_Connect (url);
if (morep < 0) {
VERBOSE (morep, ERROR, PRINTF ("can't connect on url '%s'\n", url));
return -1;
}
+ VERBOSE (morep, INFO, PRINTF ("server started at '%s'\n", url));
+
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
char *words[] = {"Quo", "cognito", "Constantius", "ultra", "mortalem", "modum", "exarsit", "ac", "nequo", "casu", "idem", "Gallus", "de", "futuris", "incertus", "agitare", "quaedam", "conducentia", "saluti", "suae", "per", "itinera", "conaretur,", "remoti", "sunt", "omnes", "de", "industria", "milites", "agentes", "in", "civitatibus", "perviis.", NULL};
while (stop) {
- int len = MOREP_Receive (fd)
+ int len = MOREP_Receive (morep);
VERBOSE (morep, INFO, PRINTF ("receive %d bytes\n", len));
- uint8_t buffer = MOREP_Get_Tx_Buffer (fd);
+ uint8_t *buffer = MOREP_Get_Tx_Buffer (morep);
len = strlen (words[i]);
memcpy (buffer, words[i++], len);
if (words[i] == NULL) {
i = 0;
}
- len = MOREP_Send (fd);
+ len = MOREP_Send (morep, 0x01, len);
VERBOSE (morep, INFO, PRINTF ("send %d bytes\n", len));
}
return 0;
}
-/**
- Verbose level
-*/
-DECLARE_VERBOSE_LEVEL (morep, INFO);
-
int main (int argc, char **argv)
{
char *url = NULL;
while (argc-- > 1) {
char *arg = *(++argv);
if (arg[0] != '-') {
- url = arg[0];
+ url = arg;
}
char c = arg[1];
switch (c) {
arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
if (arg == NULL) {
VERBOSE (ERROR, fprintf (stderr, "%s: verbose level not specified\n", progname));
- return usage (1);
+ return 1;
}
CHANGE_VERBOSE_LEVEL (morep, atoi (arg));
break;