wangzhengquan
2020-10-10 9ebe80228c7b7cb35ccaeaaa46ccf726bf71d6bd
update
20个文件已删除
2个文件已添加
10个文件已修改
3194 ■■■■■ 已修改文件
demo/Makefile 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
demo/dgram_mod_req_rep.c 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
include/usgcommon/socket_io.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lib/libusgcommon.a 补丁 | 查看 | 原始文档 | blame | 历史
lib/libusgcommon.so 补丁 | 查看 | 原始文档 | blame | 历史
src/Makefile 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/libshm_queue.a 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/array_lock_free_queue.h 322 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/array_lock_free_queue2.h 332 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/hashtable.h 41 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/linked_lock_free_queue.h 245 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/lock_free_queue.h 369 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/mem_pool.h 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/mm.h 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/shm_allocator.h 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/shm_mm.h 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/shm_queue.h 209 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/queue/include/shm_queue_wrapper.h 103 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/dmod_socket.c 524 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/include/dgram_mod_socket.h 131 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/include/dmod_socket.h 159 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/include/mod_socket.h 77 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/include/shm_socket.h 104 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/net_mod_server_socket.c 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/net_mod_server_socket.h 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/net_mod_socket.c 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/net_mod_socket_io.c 51 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/socket/net_mod_socket_io.h 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/util/include/sem_util.h 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/util/sem_util.c 150 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/util/sem_util.h 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test_net_socket/test_net_mod_socket.c 17 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
demo/Makefile
@@ -1,28 +1,40 @@
#
# Makefile for common library.
#
ROOT=..
LDLIBS+=-Wl,-rpath=$(ROOT)/lib:$(ROOT)/build/lib
# 开源工具包路径
LDDIR += -L$(ROOT)/build/lib
# 开源工具包
LDLIBS += -lshm_queue -lusgcommon -lpthread
INCLUDE += -I$(ROOT)/build/include
ROOT := ..
PLATFORM=$(shell $(ROOT)/systype.sh)
include $(ROOT)/Make.defines.$(PLATFORM)
#RPATH += -Wl,-rpath=${ROOT}/lib
# 开源工具包路径
LDDIR += -L${DEST}/lib
PROGS = dgram_mod_req_rep dgram_mod_survey dgram_mod_bus
# 开源工具包
LDLIBS += -lshm_queue -lusgcommon -lpthread
INCLUDES += -I${DEST}/include/shmqueue -I$(ROOT)/include/usgcommon
build: $(PROGS)
PROGS = ${DEST}/dgram_mod_req_rep ${DEST}/dgram_mod_survey ${DEST}/dgram_mod_bus
# test1: $(LIBCOMMON)
DEPENDENCES = $(patsubst %, %.d, $(PROGS))
# 如果包A 引用包B, B 要放在 A 后面
#LIBCOMMON=${ROOT}/lib/libusgcommon.a
build:     $(PROGS)
# class
#$(DEST)/kucker : kucker.c
clean:
    rm -f $(TEMPFILES) $(PROGS)
    rm -f $(PROGS) $(DEPENDENCES) $(TEMPFILES)
# $(LIBCOMMON):
#     @(cd $(ROOT)/common && $(MAKE))
-include $(DEPENDENCES)
include $(ROOT)/Make.common.inc
demo/dgram_mod_req_rep.c
@@ -26,7 +26,7 @@
  void *socket = dgram_mod_open_socket();
  int size;
  void *recvbuf;
  printf("client :send request%s\n", sendbuf);
  printf("client :send request %s\n", sendbuf);
  if(dgram_mod_sendandrecv(socket, sendbuf, strlen(sendbuf) + 1, port, &recvbuf, &size) == 0) {
    printf("client :received reply => %s\n", (char *)recvbuf);
    free(recvbuf);
include/usgcommon/socket_io.h
@@ -20,14 +20,14 @@
} rio_t;
/* Rio (Robust I/O) package */
ssize_t rio_readn(int fd, void *usrbuf, size_t n);
ssize_t rio_writen(int fd, void *usrbuf, size_t n);
ssize_t rio_writen(int fd, const void *usrbuf, size_t n);
void rio_readinitb(rio_t *rp, int fd); 
ssize_t    rio_readnb(rio_t *rp, void *usrbuf, size_t n);
ssize_t    rio_readlineb(rio_t *rp, char *usrbuf, size_t maxlen);
/* Wrappers for Rio package */
ssize_t Rio_readn(int fd, void *usrbuf, size_t n);
void Rio_writen(int fd, void *usrbuf, size_t n);
void Rio_writen(int fd, const void *usrbuf, size_t n);
void Rio_readinitb(rio_t *rp, int fd); 
ssize_t Rio_readnb(rio_t *rp, void *usrbuf, size_t n);
ssize_t Rio_readlineb(rio_t *rp, char *usrbuf, size_t maxlen);
lib/libusgcommon.a
Binary files differ
lib/libusgcommon.so
Binary files differ
src/Makefile
@@ -14,7 +14,7 @@
# 开源工具包
LDLIBS += -lusgcommon
INCLUDES += -I./queue -I./socket  -I./util -I$(ROOT)/include/usgcommon
INCLUDES += -I./queue -I./socket  -I$(ROOT)/include/usgcommon
SOURCES := $(wildcard *.c ./**/*.c)
OBJS   = $(patsubst %.c, $(DEST)/%.o, $(SOURCES)) 
@@ -63,7 +63,7 @@
    install -d $(PREFIX)/lib/
    install -m 644 $^ $(PREFIX)/lib/
    install -d $(PREFIX)/include/shmqueue
    install -m 644 ./*.h ./queue/*.h ./socket/*.h ./util/*.h $(PREFIX)/include/shmqueue
    install -m 644 ./*.h ./queue/*.h ./socket/*.h  $(PREFIX)/include/shmqueue
.PHONY: uninstall
src/libshm_queue.a
Binary files differ
src/queue/include/array_lock_free_queue.h
File was deleted
src/queue/include/array_lock_free_queue2.h
File was deleted
src/queue/include/hashtable.h
File was deleted
src/queue/include/linked_lock_free_queue.h
File was deleted
src/queue/include/lock_free_queue.h
File was deleted
src/queue/include/mem_pool.h
File was deleted
src/queue/include/mm.h
File was deleted
src/queue/include/shm_allocator.h
File was deleted
src/queue/include/shm_mm.h
File was deleted
src/queue/include/shm_queue.h
File was deleted
src/queue/include/shm_queue_wrapper.h
File was deleted
src/socket/dmod_socket.c
File was deleted
src/socket/include/dgram_mod_socket.h
File was deleted
src/socket/include/dmod_socket.h
File was deleted
src/socket/include/mod_socket.h
File was deleted
src/socket/include/shm_socket.h
File was deleted
src/socket/net_mod_server_socket.c
@@ -1,11 +1,10 @@
#include "net_mod_server_socket.h"
#include "socket_io.h"
#include "net_mod_socket_io.h"
 
NetModServerSocket::NetModServerSocket(int port, ShmModSocket * modsocket)
NetModServerSocket::NetModServerSocket(int port, ShmModSocket * modsocket): shm_mod_socket(modsocket)
{
    shm_mod_socket = modsocket;
  char portstr[32];
  sprintf(portstr, "%d", port);
  listenfd = Open_listenfd(portstr);
@@ -81,6 +80,8 @@
}
/* $end add_client */
/* $begin check_clients */
void  NetModServerSocket::check_clients()
{
@@ -97,10 +98,11 @@
    if ((connfd > 0) && (FD_ISSET(connfd, &pool.ready_set)))
    {
      pool.nready--;
      if ((n = Rio_readlineb(&rio, buf, MAXLINE)) != 0)
      if ((n = rio_readpkgb(&rio, buf, MAXLINE)) > 0)
      {
         
        Rio_writen(connfd, buf, n);
        Rio_writen(connfd, PKG_SEP, strlen(PKG_SEP));
       // shm_mod_socket->sendto(buf, n, msg->key);
      //   net_mod_msg_t *msg = (net_mod_msg_t*)buf;
            // if(msg.mod == PUB_SUB) {
src/socket/net_mod_server_socket.h
@@ -37,7 +37,7 @@
public:
    NetModServerSocket(int port, ShmModSocket *shm_mod_socket);
    NetModServerSocket(int port, ShmModSocket *_shm_mod_socket);
    void start();
    ~NetModServerSocket();
src/socket/net_mod_socket.c
@@ -1,5 +1,6 @@
#include "net_mod_socket.h"
#include "socket_io.h"
#include "net_mod_socket_io.h"
NetModSocket::NetModSocket(const char *host, int port) 
{
@@ -12,10 +13,11 @@
ssize_t NetModSocket::send(void *buf, size_t size) {
  int n = rio_writen(clientfd, buf, size);
  rio_writen(clientfd, PKG_SEP, strlen(PKG_SEP));
  char resp[MAXLINE];
  int ss;
  ss = rio_readlineb(&rio, resp, MAXLINE);
  ss = rio_readpkgb(&rio, resp, MAXLINE);
  puts(resp);
  return n;
}
src/socket/net_mod_socket_io.c
New file
@@ -0,0 +1,51 @@
#include "net_mod_socket_io.h"
#include "socket_io.h"
ssize_t rio_readpkgb(rio_t *rp, char *usrbuf, size_t maxlen)
{
  int n, rc;
  char c;
  char *bufp = usrbuf;
  int pkg_sep_i = 0;
  int pkg_sep_len = strlen(PKG_SEP);
  const char * pkg_sep = PKG_SEP;
  for (n = 0; n < maxlen; n++)
  {
    if ((rc = rio_readnb(rp, &c, 1)) == 1)
    {
      *bufp++ = c;
      if(c == *(pkg_sep + pkg_sep_i)) {
        pkg_sep_i++;
        if(pkg_sep_i == pkg_sep_len) {
          break;
        }
      } else {
        pkg_sep_i = 0;
      }
    }
    else if (rc == 0)
    {
      if (n == 0)
        return 0; /* EOF, no data read */
      else
        break;    /* EOF, some data was read */
    }
    else
      return -1;    /* Error */
  }
  if(pkg_sep_i == pkg_sep_len) {
    *(bufp - pkg_sep_len) = 0;
    return n - pkg_sep_len;
  } else {
    return -1;
  }
}
src/socket/net_mod_socket_io.h
New file
@@ -0,0 +1,10 @@
#ifndef __NET_MODE_SOCKET_IO_H__
#define __NET_MODE_SOCKET_IO_H__
#include "socket_io.h"
#include "usg_common.h"
#define PKG_SEP "\r\n\r\n"
ssize_t rio_readpkgb(rio_t *rp, char *usrbuf, size_t maxlen);
#endif
src/util/include/sem_util.h
File was deleted
src/util/sem_util.c
File was deleted
src/util/sem_util.h
File was deleted
test_net_socket/test_net_mod_socket.c
@@ -1,11 +1,16 @@
#include "net_mod_server_socket.h"
#include "net_mod_socket.h"
#include "shm_mm.h"
#include "dgram_mod_socket.h"
void server() {
    ShmModSocket * m_socket = new ShmModSocket();
    NetModServerSocket serverSocket(5000, m_socket);
    serverSocket.start();
    // void *socket = dgram_mod_open_socket();
    // ShmModSocket tt;
     ShmModSocket * m_socket = new ShmModSocket;
    // NetModServerSocket(5000,     NULL);
    NetModServerSocket *serverSocket  = new NetModServerSocket(5000, m_socket);
    serverSocket->start();
}
void client(){
@@ -20,6 +25,7 @@
int main(int argc, char *argv[]) {
    shm_init(512);
    if (argc < 2) {
     fprintf(stderr, "Usage: %s %s|%s\n", argv[0], "server", "client");
     return 1;
@@ -31,4 +37,7 @@
  if (strcmp("client", argv[1]) == 0)
     client();
}
}