Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding the client library to the build and added update, next and pea…

…k functionality to it.
  • Loading branch information...
commit 34c69859e436dd892d895ccaddd1639cc4d1d082 1 parent 3872374
@ngerakines authored
View
58 autom4te.cache/requests
@@ -75,11 +75,11 @@
'_AM_AUTOCONF_VERSION' => 1,
'AM_DISABLE_SHARED' => 1,
'_LTDL_SETUP' => 1,
- '_LT_AC_LANG_CXX' => 1,
'AM_PROG_LIBTOOL' => 1,
- 'AC_LIB_LTDL' => 1,
- '_LT_AC_FILE_LTDLL_C' => 1,
+ '_LT_AC_LANG_CXX' => 1,
'AM_PROG_LD' => 1,
+ '_LT_AC_FILE_LTDLL_C' => 1,
+ 'AC_LIB_LTDL' => 1,
'AU_DEFUN' => 1,
'AC_PROG_NM' => 1,
'AC_LIBTOOL_DLOPEN' => 1,
@@ -103,29 +103,29 @@
'AC_LTDL_OBJDIR' => 1,
'_LT_PATH_TOOL_PREFIX' => 1,
'AC_LIBTOOL_RC' => 1,
- 'AC_DISABLE_FAST_INSTALL' => 1,
'_LT_AC_PROG_ECHO_BACKSLASH' => 1,
- '_LT_AC_SYS_LIBPATH_AIX' => 1,
- '_LT_AC_TRY_DLOPEN_SELF' => 1,
+ 'AC_DISABLE_FAST_INSTALL' => 1,
'include' => 1,
+ '_LT_AC_TRY_DLOPEN_SELF' => 1,
+ '_LT_AC_SYS_LIBPATH_AIX' => 1,
'LT_AC_PROG_SED' => 1,
'AM_ENABLE_SHARED' => 1,
'LTDL_INSTALLABLE' => 1,
'_LT_AC_LANG_GCJ_CONFIG' => 1,
'AC_ENABLE_SHARED' => 1,
- 'AC_ENABLE_STATIC' => 1,
'AC_LIBTOOL_SYS_HARD_LINK_LOCKS' => 1,
+ 'AC_ENABLE_STATIC' => 1,
'_LT_AC_TAGVAR' => 1,
'AC_LIBTOOL_LANG_F77_CONFIG' => 1,
'AM_CONDITIONAL' => 1,
'LT_LIB_DLLOAD' => 1,
- 'LTDL_INIT' => 1,
'LTVERSION_VERSION' => 1,
- 'AM_PROG_INSTALL_SH' => 1,
+ 'LTDL_INIT' => 1,
'm4_include' => 1,
+ 'AM_PROG_INSTALL_SH' => 1,
'AC_PROG_EGREP' => 1,
- '_AC_AM_CONFIG_HEADER_HOOK' => 1,
'AC_PATH_MAGIC' => 1,
+ '_AC_AM_CONFIG_HEADER_HOOK' => 1,
'AC_LTDL_SYSSEARCHPATH' => 1,
'AM_MAKE_INCLUDE' => 1,
'LT_CMD_MAX_LEN' => 1,
@@ -170,11 +170,11 @@
'AM_PROG_NM' => 1,
'AC_LIBLTDL_CONVENIENCE' => 1,
'AC_DEPLIBS_CHECK_METHOD' => 1,
- 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
'AC_LIBLTDL_INSTALLABLE' => 1,
+ 'AM_SET_CURRENT_AUTOMAKE_VERSION' => 1,
'AC_LTDL_ENABLE_INSTALL' => 1,
- 'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1,
'LT_PROG_GCJ' => 1,
+ 'AC_LIBTOOL_SYS_DYNAMIC_LINKER' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_DISABLE_STATIC' => 1,
'LT_PATH_NM' => 1,
@@ -182,28 +182,28 @@
'_LT_AC_LOCK' => 1,
'_LT_AC_LANG_RC_CONFIG' => 1,
'LT_SYS_MODULE_PATH' => 1,
- 'AC_LIBTOOL_POSTDEP_PREDEP' => 1,
'LT_WITH_LTDL' => 1,
+ 'AC_LIBTOOL_POSTDEP_PREDEP' => 1,
'AC_LTDL_SHLIBPATH' => 1,
'AM_AUX_DIR_EXPAND' => 1,
- '_LT_AC_LANG_F77_CONFIG' => 1,
'AC_LIBTOOL_PROG_COMPILER_NO_RTTI' => 1,
- '_AM_SET_OPTIONS' => 1,
+ '_LT_AC_LANG_F77_CONFIG' => 1,
'_LT_COMPILER_OPTION' => 1,
- '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
+ '_AM_SET_OPTIONS' => 1,
'AM_RUN_LOG' => 1,
- 'AC_LIBTOOL_PICMODE' => 1,
- 'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1,
+ '_AM_OUTPUT_DEPENDENCY_COMMANDS' => 1,
'AC_LTDL_SYS_DLOPEN_DEPLIBS' => 1,
- 'LT_PATH_LD' => 1,
+ 'AC_LIBTOOL_SYS_OLD_ARCHIVE' => 1,
+ 'AC_LIBTOOL_PICMODE' => 1,
'AC_CHECK_LIBM' => 1,
+ 'LT_PATH_LD' => 1,
'AC_LIBTOOL_SYS_LIB_STRIP' => 1,
'_AM_MANGLE_OPTION' => 1,
- 'AC_LTDL_SYMBOL_USCORE' => 1,
'AC_LIBTOOL_SYS_MAX_CMD_LEN' => 1,
+ 'AC_LTDL_SYMBOL_USCORE' => 1,
'AM_SET_DEPDIR' => 1,
- '_LT_CC_BASENAME' => 1,
'_LT_LIBSOURCES' => 1,
+ '_LT_CC_BASENAME' => 1,
'_LT_LIBOBJ' => 1
}
], 'Autom4te::Request' ),
@@ -219,15 +219,15 @@
'configure.ac'
],
{
- 'AM_PROG_F77_C_O' => 1,
'_LT_AC_TAGCONFIG' => 1,
- 'm4_pattern_forbid' => 1,
+ 'AM_PROG_F77_C_O' => 1,
'AC_INIT' => 1,
+ 'm4_pattern_forbid' => 1,
'AC_CANONICAL_TARGET' => 1,
- 'AC_SUBST' => 1,
'AC_CONFIG_LIBOBJ_DIR' => 1,
- 'AC_FC_SRCEXT' => 1,
+ 'AC_SUBST' => 1,
'AC_CANONICAL_HOST' => 1,
+ 'AC_FC_SRCEXT' => 1,
'AC_PROG_LIBTOOL' => 1,
'AM_INIT_AUTOMAKE' => 1,
'AC_CONFIG_SUBDIRS' => 1,
@@ -235,8 +235,8 @@
'LT_CONFIG_LTDL_DIR' => 1,
'AC_CONFIG_LINKS' => 1,
'AC_REQUIRE_AUX_FILE' => 1,
- 'm4_sinclude' => 1,
'LT_SUPPORTED_TAG' => 1,
+ 'm4_sinclude' => 1,
'AM_MAINTAINER_MODE' => 1,
'AM_GNU_GETTEXT_INTL_SUBDIR' => 1,
'_m4_warn' => 1,
@@ -253,11 +253,11 @@
'AH_OUTPUT' => 1,
'_AM_SUBST_NOTMAKE' => 1,
'AC_CONFIG_AUX_DIR' => 1,
- 'sinclude' => 1,
- 'AM_PROG_CC_C_O' => 1,
'm4_pattern_allow' => 1,
- 'AC_CANONICAL_SYSTEM' => 1,
+ 'AM_PROG_CC_C_O' => 1,
+ 'sinclude' => 1,
'AM_CONDITIONAL' => 1,
+ 'AC_CANONICAL_SYSTEM' => 1,
'AC_CONFIG_HEADERS' => 1,
'AC_DEFINE_TRACE_LITERAL' => 1,
'm4_include' => 1,
View
5 src/Makefile.am
@@ -1,8 +1,11 @@
## Process this file with automake to produce Makefile.in
-bin_PROGRAMS = barbershop benchmark
+bin_PROGRAMS = barbershop client benchmark
barbershop_SOURCES = barbershop.c barbershop.h bst.c bst.h scores.c scores.h stats.h
barbershop_CFLAGS = $(OPTIMIZATION) -Wall $(ARCH) $(PROF)
+client_SOURCES = client.c
+client_CFLAGS = $(OPTIMIZATION) -Wall $(ARCH) $(PROF)
+
benchmark_SOURCES = benchmark.c
benchmark_CFLAGS = $(OPTIMIZATION) -Wall $(ARCH) $(PROF)
View
33 src/Makefile.in
@@ -32,7 +32,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
-bin_PROGRAMS = barbershop$(EXEEXT) benchmark$(EXEEXT)
+bin_PROGRAMS = barbershop$(EXEEXT) client$(EXEEXT) benchmark$(EXEEXT)
subdir = src
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -58,6 +58,12 @@ benchmark_LDADD = $(LDADD)
benchmark_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(benchmark_CFLAGS) \
$(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@
+am_client_OBJECTS = client-client.$(OBJEXT)
+client_OBJECTS = $(am_client_OBJECTS)
+client_LDADD = $(LDADD)
+client_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+ --mode=link $(CCLD) $(client_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+ $(LDFLAGS) -o $@
DEFAULT_INCLUDES = -I. -I$(top_builddir)@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/build-aux/depcomp
am__depfiles_maybe = depfiles
@@ -70,8 +76,9 @@ CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
-SOURCES = $(barbershop_SOURCES) $(benchmark_SOURCES)
-DIST_SOURCES = $(barbershop_SOURCES) $(benchmark_SOURCES)
+SOURCES = $(barbershop_SOURCES) $(benchmark_SOURCES) $(client_SOURCES)
+DIST_SOURCES = $(barbershop_SOURCES) $(benchmark_SOURCES) \
+ $(client_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@@ -187,6 +194,8 @@ top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
barbershop_SOURCES = barbershop.c barbershop.h bst.c bst.h scores.c scores.h stats.h
barbershop_CFLAGS = $(OPTIMIZATION) -Wall $(ARCH) $(PROF)
+client_SOURCES = client.c
+client_CFLAGS = $(OPTIMIZATION) -Wall $(ARCH) $(PROF)
benchmark_SOURCES = benchmark.c
benchmark_CFLAGS = $(OPTIMIZATION) -Wall $(ARCH) $(PROF)
all: all-am
@@ -256,6 +265,9 @@ barbershop$(EXEEXT): $(barbershop_OBJECTS) $(barbershop_DEPENDENCIES)
benchmark$(EXEEXT): $(benchmark_OBJECTS) $(benchmark_DEPENDENCIES)
@rm -f benchmark$(EXEEXT)
$(benchmark_LINK) $(benchmark_OBJECTS) $(benchmark_LDADD) $(LIBS)
+client$(EXEEXT): $(client_OBJECTS) $(client_DEPENDENCIES)
+ @rm -f client$(EXEEXT)
+ $(client_LINK) $(client_OBJECTS) $(client_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@@ -267,6 +279,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/barbershop-bst.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/barbershop-scores.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/benchmark-benchmark.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client-client.Po@am__quote@
.c.o:
@am__fastdepCC_TRUE@ $(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -345,6 +358,20 @@ benchmark-benchmark.obj: benchmark.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(benchmark_CFLAGS) $(CFLAGS) -c -o benchmark-benchmark.obj `if test -f 'benchmark.c'; then $(CYGPATH_W) 'benchmark.c'; else $(CYGPATH_W) '$(srcdir)/benchmark.c'; fi`
+client-client.o: client.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(client_CFLAGS) $(CFLAGS) -MT client-client.o -MD -MP -MF $(DEPDIR)/client-client.Tpo -c -o client-client.o `test -f 'client.c' || echo '$(srcdir)/'`client.c
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/client-client.Tpo $(DEPDIR)/client-client.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='client.c' object='client-client.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(client_CFLAGS) $(CFLAGS) -c -o client-client.o `test -f 'client.c' || echo '$(srcdir)/'`client.c
+
+client-client.obj: client.c
+@am__fastdepCC_TRUE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(client_CFLAGS) $(CFLAGS) -MT client-client.obj -MD -MP -MF $(DEPDIR)/client-client.Tpo -c -o client-client.obj `if test -f 'client.c'; then $(CYGPATH_W) 'client.c'; else $(CYGPATH_W) '$(srcdir)/client.c'; fi`
+@am__fastdepCC_TRUE@ mv -f $(DEPDIR)/client-client.Tpo $(DEPDIR)/client-client.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='client.c' object='client-client.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(client_CFLAGS) $(CFLAGS) -c -o client-client.obj `if test -f 'client.c'; then $(CYGPATH_W) 'client.c'; else $(CYGPATH_W) '$(srcdir)/client.c'; fi`
+
mostlyclean-libtool:
-rm -f *.lo
View
4 src/barbershop.c
@@ -130,7 +130,6 @@ void on_read(int fd, short ev, void *arg) {
app_stats.updates += 1;
reply(fd, "+OK\r\n");
} else if (ntokens == 2 && strcmp(tokens[COMMAND_TOKEN].value, "PEAK") == 0) {
- printf("received a 'PEAK' command\n");
int next;
pthread_mutex_lock(&scores_mutex);
PeakNext(scores, &next);
@@ -139,7 +138,6 @@ void on_read(int fd, short ev, void *arg) {
sprintf(msg, "+%d\r\n", next);
reply(fd, msg);
} else if (ntokens == 2 && strcmp(tokens[COMMAND_TOKEN].value, "NEXT") == 0) {
- printf("received a 'NEXT' command\n");
int next;
pthread_mutex_lock(&scores_mutex);
scores = NextItem(scores, &next);
@@ -268,7 +266,7 @@ void load_snapshot(char *filename) {
items = Insert(item_id, score, items);
scores = promoteItem(scores, score, item_id, -1);
app_stats.items += 1;
- printf("Loading %d with score %d\n", item_id, score);
+ // printf("Loading %d with score %d\n", item_id, score);
}
pthread_mutex_unlock(&scores_mutex);
fclose(file_in);
View
238 src/client.c
@@ -2,51 +2,211 @@
Copyright (c) 2010 Nick Gerakines <nick at gerakines dot net>
*/
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <sys/queue.h>
+#include <stdlib.h>
+#include <err.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
+#include <string.h>
+
+#include <getopt.h>
+#include <signal.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <unistd.h>
+
+const int UNKNOWN = 0;
+const int UPDATE = 1;
+const int NEXT = 2;
+const int PEAK = 3;
+const int INFO = 4;
+
+void send_command(int sd, char *command);
+
+int main(int argc, char **argv) {
+ char *ipaddress = "127.0.0.1";
+ int port = 8002;
+
+ int c;
+ while (1) {
+ static struct option long_options[] = {
+ {"ip", required_argument, 0, 'i'},
+ {"port", required_argument, 0, 'p'},
+ {0, 0, 0, 0}
+ };
+ int option_index = 0;
+ c = getopt_long(argc, argv, "i:p:", long_options, &option_index);
+ if (c == -1) { break; }
+ switch (c) {
+ case 0:
+ if (long_options[option_index].flag != 0) { break; }
+ printf ("option %s", long_options[option_index].name);
+ if (optarg) { printf(" with arg %s", optarg); }
+ printf("\n");
+ break;
+ case 'i':
+ ipaddress = optarg;
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ case '?':
+ /* getopt_long already printed an error message. */
+ break;
+ default:
+ abort();
+ }
+ }
+
+ int action = -1;
+
+ if (argc - optind == 0) {
+ printf("Command not provided.\n");
+ printf("usage: client [--ip=] [--port=] <command> [... command arguments]\n");
+ exit(1);
+ }
+
+ if (strcmp(argv[optind], "update") == 0) {
+ if (argc - optind != 3) {
+ printf("The 'update' command requires 2 command parameters.\n");
+ printf("usage: client [--ip=] [--port=] update <item id> <priority value>\n");
+ exit(1);
+ }
+ action = 1;
+ }
-void error(char *msg) {
- perror(msg);
- exit(0);
+ if (strcmp(argv[optind], "next") == 0) {
+ if (argc - optind != 1) {
+ printf("The 'next' command requires 0 command parameters.\n");
+ printf("usage: client [--ip=] [--port=] next\n");
+ exit(1);
+ }
+ action = 2;
+ }
+
+ if (strcmp(argv[optind], "peak") == 0) {
+ if (argc - optind != 1) {
+ printf("The 'peak' command requires 0 command parameters.\n");
+ printf("usage: client [--ip=] [--port=] peak\n");
+ exit(1);
+ }
+ action = 3;
+ }
+
+ if (strcmp(argv[optind], "info") == 0) {
+ if (argc - optind != 1) {
+ printf("The 'info' command requires 0 command parameters.\n");
+ printf("usage: client [--ip=] [--port=] info\n");
+ exit(1);
+ }
+ action = 4;
+ }
+
+ if (action == 0) {
+ printf("Invalid command given, should be either update, next, peak or info.\n");
+ printf("usage: client [--ip=] [--port=] <command> [... command arguments]\n");
+ exit(1);
+ }
+
+ struct hostent *hp;
+ struct sockaddr_in pin;
+ int sd;
+
+ if ((hp = gethostbyname(ipaddress)) == 0) {
+ perror("gethostbyname");
+ exit(1);
+ }
+
+ memset(&pin, 0, sizeof(pin));
+ pin.sin_family = AF_INET;
+ pin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr;
+ pin.sin_port = htons(port);
+
+ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+ perror("socket");
+ exit(1);
+ }
+
+ if (connect(sd,(struct sockaddr *) &pin, sizeof(pin)) == -1) {
+ perror("connect");
+ exit(1);
+ }
+
+ int item_id = 0;
+ int priority = 0;
+ char msg[32];
+
+ switch (action) {
+ case 1:
+ item_id = atoi(argv[optind + 1]);
+ priority = atoi(argv[optind + 2]);
+ sprintf(msg, "UPDATE %d %d\r\n", item_id, priority);
+ send_command(sd, msg);
+ break;
+ case 2:
+ send_command(sd, "NEXT\r\n");
+ break;
+ case 3:
+ send_command(sd, "PEAK\r\n");
+ break;
+ case 4:
+ default:
+ break;
+ }
+
+ close(sd);
+
+ return 0;
}
-int main(int argc, char *argv[])
-{
- int sockfd, portno, n;
-
- struct sockaddr_in serv_addr;
- struct hostent *server;
-
- char buffer[256];
- if (argc < 3) {
- fprintf(stderr,"usage %s hostname port\n", argv[0]);
- exit(0);
- }
- portno = atoi(argv[2]);
- sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd < 0)
- error("ERROR opening socket");
- server = gethostbyname(argv[1]);
- if (server == NULL) {
- fprintf(stderr,"ERROR, no such host\n");
- exit(0);
- }
- bzero((char *) &serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- bcopy((char *)server->h_addr,
- (char *)&serv_addr.sin_addr.s_addr,
- server->h_length);
- serv_addr.sin_port = htons(portno);
- if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0)
- error("ERROR connecting");
- n = write(sockfd, "update 11223344 1\n", strlen("update 11223344 1\n"));
- if (n < 0) { error("ERROR writing to socket"); }
- bzero(buffer,256);
- n = read(sockfd,buffer,255);
- if (n < 0) { error("ERROR reading from socket"); }
- printf("%s\n",buffer);
- return 0;
+void send_command(int sd, char *command) {
+ if (send(sd, command, strlen(command), 0) == -1) {
+ perror("send");
+ exit(1);
+ }
+ char buf[300];
+ int numbytes;
+ if((numbytes = recv(sd, buf, 300-1, 0)) == -1) {
+ perror("recv()");
+ exit(1);
+ }
+
+ char *resp = NULL;
+ int buf_len;
+
+ switch (buf[0]) {
+ case '-':
+ break;
+ case '+':
+ case ':':
+ buf_len = strlen(buf) - 3;
+ if (buf_len >= 2) {
+ resp = malloc(1 + buf_len);
+ memcpy(resp, buf+1, buf_len);
+ resp[buf_len] = 0;
+ printf("%s\n", resp);
+ free(resp);
+ } else {
+ printf("protocol error \n");
+ }
+ break;
+ default:
+ printf("protocol error, got '%c' as reply type byte\n", buf[0]);
+ break;
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.