Permalink
Browse files

move to company svn

  • Loading branch information...
auxten committed May 9, 2012
1 parent a30c0ac commit a3165ad7d58d0d2e8f559eb4df14dcd2d59966f8
Showing with 222 additions and 182 deletions.
  1. +14 −0 example/client.cpp
  2. +1 −1 src/Makefile.am
  3. +20 −11 src/Makefile.in
  4. +8 −7 src/aclocal.m4
  5. +103 −7 src/async_clnt.cpp
  6. +26 −0 src/async_clnt.h
  7. +2 −1 src/async_pool.h
  8. +6 −0 src/async_threads.cpp
  9. +0 −14 src/aysnc_clnt.h
  10. +4 −4 src/configure
  11. +18 −9 src/gingko.h
  12. +4 −4 src/hash/Makefile.in
  13. +8 −7 src/hash/aclocal.m4
  14. +4 −4 src/hash/configure
  15. +4 −49 src/missing
  16. +0 −64 src/socket.cpp
View
@@ -6,6 +6,7 @@
*/
#include "gko.h"
+#include "async_clnt.h"
/// gingko global stuff
s_gingko_global_t gko;
@@ -36,7 +37,10 @@ int main(int argc, char** argv)
pthread_attr_t g_attr;
pthread_t vnode_pthread[T_NUM];
void *status;
+ unsigned short proto_ver;
+ unsigned int msg_len;
+ /*
if (pthread_attr_init(&g_attr) != 0)
{
gko_log(FATAL, FLF("pthread_mutex_destroy error"));
@@ -70,6 +74,16 @@ int main(int argc, char** argv)
return -1;
}
}
+ */
+ char buf[20] = {'\0'};
+ fill_cmd_head(buf, INT32_MAX);
+ parse_cmd_head(buf, &proto_ver, &msg_len);
+ gko_log(DEBUG, "%s %d", buf, msg_len);
+ std::vector<struct conn_client> conn_vec;
+ std::vector<s_host_t> srv_vec(1000, server);
+ connect_hosts(srv_vec, &conn_vec);
+ sleep(10);
+ disconnect_hosts(conn_vec);
return 0;
}
View
@@ -11,6 +11,6 @@ export INCLUDES
noinst_LIBRARIES=libgko.a
DEFS+=-O0 -D_GNU_SOURCE -ggdb -funsigned-char
-libgko_a_SOURCES=async_threads.cpp async_conn.cpp \
+libgko_a_SOURCES=async_threads.cpp async_conn.cpp async_clnt.cpp \
gingko_base.cpp log.cpp socket.cpp limit.cpp
libgko_a_LDFLAGS=-O0 -D_GNU_SOURCE -ggdb -funsigned-char
View
@@ -1,4 +1,4 @@
-# Makefile.in generated by automake 1.11.2 from Makefile.am.
+# Makefile.in generated by automake 1.11.3 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@@ -36,7 +36,7 @@ subdir = .
DIST_COMMON = README $(am__configure_deps) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in $(srcdir)/config.h.in \
$(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
- depcomp install-sh missing
+ TODO depcomp install-sh missing
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = $(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
@@ -53,8 +53,8 @@ ARFLAGS = cru
libgko_a_AR = $(AR) $(ARFLAGS)
libgko_a_LIBADD =
am_libgko_a_OBJECTS = async_threads.$(OBJEXT) async_conn.$(OBJEXT) \
- gingko_base.$(OBJEXT) log.$(OBJEXT) socket.$(OBJEXT) \
- limit.$(OBJEXT)
+ async_clnt.$(OBJEXT) gingko_base.$(OBJEXT) log.$(OBJEXT) \
+ socket.$(OBJEXT) limit.$(OBJEXT)
libgko_a_OBJECTS = $(am_libgko_a_OBJECTS)
DEFAULT_INCLUDES = -I.@am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -86,9 +86,11 @@ DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
am__remove_distdir = \
- { test ! -d "$(distdir)" \
- || { find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
- && rm -fr "$(distdir)"; }; }
+ if test -d "$(distdir)"; then \
+ find "$(distdir)" -type d ! -perm -200 -exec chmod u+w {} ';' \
+ && rm -rf "$(distdir)" \
+ || { sleep 5 && rm -rf "$(distdir)"; }; \
+ else :; fi
am__relativize = \
dir0=`pwd`; \
sed_first='s,^\([^/]*\)/.*$$,\1,'; \
@@ -222,7 +224,7 @@ INCLUDES = -I$(srcdir)/src\
#noinst_PROGRAMS=gingko_serv gingko_clnt serv_unittest clnt_unittest
noinst_LIBRARIES = libgko.a
-libgko_a_SOURCES = async_threads.cpp async_conn.cpp \
+libgko_a_SOURCES = async_threads.cpp async_conn.cpp async_clnt.cpp \
gingko_base.cpp log.cpp socket.cpp limit.cpp
libgko_a_LDFLAGS = -O0 -D_GNU_SOURCE -ggdb -funsigned-char
@@ -283,7 +285,7 @@ distclean-hdr:
clean-noinstLIBRARIES:
-test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES)
-libgko.a: $(libgko_a_OBJECTS) $(libgko_a_DEPENDENCIES)
+libgko.a: $(libgko_a_OBJECTS) $(libgko_a_DEPENDENCIES) $(EXTRA_libgko_a_DEPENDENCIES)
-rm -f libgko.a
$(libgko_a_AR) libgko.a $(libgko_a_OBJECTS) $(libgko_a_LIBADD)
$(RANLIB) libgko.a
@@ -294,6 +296,7 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/async_clnt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/async_conn.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/async_threads.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gingko_base.Po@am__quote@
@@ -525,6 +528,10 @@ dist-bzip2: distdir
tardir=$(distdir) && $(am__tar) | BZIP2=$${BZIP2--9} bzip2 -c >$(distdir).tar.bz2
$(am__remove_distdir)
+dist-lzip: distdir
+ tardir=$(distdir) && $(am__tar) | lzip -c $${LZIP_OPT--9} >$(distdir).tar.lz
+ $(am__remove_distdir)
+
dist-lzma: distdir
tardir=$(distdir) && $(am__tar) | lzma -9 -c >$(distdir).tar.lzma
$(am__remove_distdir)
@@ -561,6 +568,8 @@ distcheck: dist
bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\
*.tar.lzma*) \
lzma -dc $(distdir).tar.lzma | $(am__untar) ;;\
+ *.tar.lz*) \
+ lzip -dc $(distdir).tar.lz | $(am__untar) ;;\
*.tar.xz*) \
xz -dc $(distdir).tar.xz | $(am__untar) ;;\
*.tar.Z*) \
@@ -747,8 +756,8 @@ uninstall-am:
.PHONY: $(RECURSIVE_CLEAN_TARGETS) $(RECURSIVE_TARGETS) CTAGS GTAGS \
all all-am am--refresh check check-am clean clean-generic \
clean-noinstLIBRARIES ctags ctags-recursive dist dist-all \
- dist-bzip2 dist-gzip dist-lzma dist-shar dist-tarZ dist-xz \
- dist-zip distcheck distclean distclean-compile \
+ dist-bzip2 dist-gzip dist-lzip dist-lzma dist-shar dist-tarZ \
+ dist-xz dist-zip distcheck distclean distclean-compile \
distclean-generic distclean-hdr distclean-tags distcleancheck \
distdir distuninstallcheck dvi dvi-am html html-am info \
info-am install install-am install-data install-data-am \
View
@@ -1,4 +1,4 @@
-# generated automatically by aclocal 1.11.2 -*- Autoconf -*-
+# generated automatically by aclocal 1.11.3 -*- Autoconf -*-
# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation,
@@ -38,7 +38,7 @@ AC_DEFUN([AM_AUTOMAKE_VERSION],
[am__api_version='1.11'
dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to
dnl require some minimum version. Point them to the right macro.
-m4_if([$1], [1.11.2], [],
+m4_if([$1], [1.11.3], [],
[AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl
])
@@ -54,7 +54,7 @@ m4_define([_AM_AUTOCONF_VERSION], [])
# Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced.
# This function is AC_REQUIREd by AM_INIT_AUTOMAKE.
AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION],
-[AM_AUTOMAKE_VERSION([1.11.2])dnl
+[AM_AUTOMAKE_VERSION([1.11.3])dnl
m4_ifndef([AC_AUTOCONF_VERSION],
[m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl
_AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))])
@@ -886,7 +886,7 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
# Check how to create a tarball. -*- Autoconf -*-
-# Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+# Copyright (C) 2004, 2005, 2012 Free Software Foundation, Inc.
#
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
@@ -908,10 +908,11 @@ AC_DEFUN([AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE($@)])
# a tarball read from stdin.
# $(am__untar) < result.tar
AC_DEFUN([_AM_PROG_TAR],
-[# Always define AMTAR for backward compatibility.
-AM_MISSING_PROG([AMTAR], [tar])
+[# Always define AMTAR for backward compatibility. Yes, it's still used
+# in the wild :-( We should find a proper way to deprecate it ...
+AC_SUBST([AMTAR], ['$${TAR-tar}'])
m4_if([$1], [v7],
- [am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'],
+ [am__tar='$${TAR-tar} chof - "$$tardir"' am__untar='$${TAR-tar} xf -'],
[m4_case([$1], [ustar],, [pax],,
[m4_fatal([Unknown tar format])])
AC_MSG_CHECKING([how to create a $1 tar archive])
View
@@ -5,36 +5,120 @@
* Author: auxten
*/
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include "config.h"
+#include "gingko.h"
+#include "log.h"
+#include "socket.h"
+#ifdef __APPLE__
+#include <poll.h>
+#else
+#include <sys/poll.h>
+#endif /** __APPLE__ **/
+
#include "async_pool.h"
#include "socket.h"
+/**
+ * @brief non-blocking version connect
+ *
+ * @see
+ * @note
+ * @author auxten <auxtenwpc@gmail.com>
+ * @date Apr 22, 2012
+ **/
+int nb_connect(const s_host_t * h, struct conn_client* conn)
+{
+ int sock = -1;
+ int ret = -1;
+ struct sockaddr_in channel;
+ in_addr_t host;
+ int addr_len;
+
+ addr_len = getaddr_my(h->addr, &host);
+ if (FAIL_CHECK(!addr_len))
+ {
+ gko_log(WARNING, "gethostbyname %s error", h->addr);
+ ret = -1;
+ goto NB_CONNECT_END;
+ }
+ conn->client_addr = host;
+ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (FAIL_CHECK(sock < 0))
+ {
+ gko_log(WARNING, "get socket error");
+ ret = -1;
+ goto NB_CONNECT_END;
+ }
+
+ memset(&channel, 0, sizeof(channel));
+ channel.sin_family = AF_INET;
+ memcpy(&channel.sin_addr.s_addr, &host, addr_len);
+ channel.sin_port = htons(h->port);
+
+ /** set the connect non-blocking then blocking for add timeout on connect **/
+ if (FAIL_CHECK(setnonblock(sock) < 0))
+ {
+ gko_log(WARNING, "set socket non-blocking error");
+ ret = -1;
+ goto NB_CONNECT_END;
+ }
+
+ /** connect and send the msg **/
+ if (FAIL_CHECK(connect(sock, (struct sockaddr *) &channel, sizeof(channel)) &&
+ errno != EINPROGRESS))
+ {
+ gko_log(WARNING, "connect error");
+ ret = HOST_DOWN_FAIL;
+ goto NB_CONNECT_END;
+ }
+
+ ret = sock;
+
+ NB_CONNECT_END:
+ ///
+ if (ret < 0 && sock >= 0)
+ {
+ close_socket(sock);
+ }
+ return ret;
+}
+
int connect_hosts(const std::vector<s_host_t> & host_vec,
std::vector<struct conn_client> * conn_vec)
{
- struct conn_client conn;
- memset(&conn, 0, sizeof(conn));
int conn_ok = 0;
int conn_err = 0;
if (host_vec.size() <= 0 || conn_vec == NULL)
{
return -1;
}
+
+ conn_vec->clear();
+
/// perform non-blocking connect
- for (std::vector<s_host_t>::iterator it = host_vec.begin();
+ for (std::vector<s_host_t>::const_iterator it = host_vec.begin();
it != host_vec.end();
it++)
{
int nb_conn_sock;
struct conn_client clnt;
- clnt.client_addr = it->
- nb_conn_sock = nb_connect(&(*it));
+ /// connect and set in_addr_t to clnt->client_addr
+ nb_conn_sock = nb_connect(&(*it), &clnt);
if (nb_conn_sock < 0)
{
+ char ip[18] = {'\0'};
clnt.client_fd = -1;
clnt.state = conn_connect_fail;
conn_err++;
+ gko_log(DEBUG, "connect fail for %s:%d failed",
+ inet_neta(clnt.client_addr, ip, 17), clnt.client_port);
}
else
{
@@ -51,12 +135,24 @@ int connect_hosts(const std::vector<s_host_t> & host_vec,
int disconnect_hosts(std::vector<struct conn_client> & conn_vec)
{
- for(std::vector<struct conn_client>::iterator it = conn_vec.begin();
+ for (std::vector<struct conn_client>::iterator it = conn_vec.begin();
it != conn_vec.end();
it++)
{
- close(it->client_fd)
+ if (it->state != conn_closed)
+ {
+ char ip[18] = {'\0'};
+ if (close(it->client_fd) != 0)
+ gko_log(DEBUG, "close fd failed for %s:%d",
+ inet_neta(it->client_addr, ip, 17), it->client_port);
+ it->state = conn_closed;
+ }
}
+ return 0;
+}
+
+int fill_request(const char * request, const int req_len, std::vector<struct conn_client> * conn_vec)
+{
return 0;
}
View
@@ -0,0 +1,26 @@
+/*
+ * aysnc_clnt.h
+ *
+ * Created on: May 4, 2012
+ * Author: auxten
+ */
+
+#ifndef AYSNC_CLNT_H_
+#define AYSNC_CLNT_H_
+
+/**
+ * @brief non-blocking version connect
+ *
+ * @see
+ * @note
+ * @author auxten <auxtenwpc@gmail.com>
+ * @date Apr 22, 2012
+ **/
+int nb_connect(const s_host_t * h, struct conn_client* conn);
+
+int connect_hosts(const std::vector<s_host_t> & host_vec,
+ std::vector<struct conn_client> * conn_vec);
+
+int disconnect_hosts(std::vector<struct conn_client> & conn_vec);
+
+#endif /* AYSNC_CLNT_H_ */
View
@@ -59,6 +59,7 @@ enum conn_states {
conn_timeout,
conn_reseted,
conn_connect_fail,
+ conn_closed,
conn_max_state /**< Max state value (used for assertion) */
};
@@ -68,7 +69,7 @@ struct conn_client
{
int id;
int client_fd;
- unsigned long client_addr;
+ in_addr_t client_addr;
int client_port;
unsigned int conn_time;
func_t handle_client;
Oops, something went wrong.

0 comments on commit a3165ad

Please sign in to comment.