20个文件已删除
2个文件已添加
10个文件已修改
| | |
| | | # |
| | | # 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 |
| | | |
| | | |
| | | |
| | |
| | | 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); |
| | |
| | | } 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); |
| | |
| | | # 开源工具包 |
| | | 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)) |
| | |
| | | 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 |
| | |
| | | #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); |
| | |
| | | } |
| | | /* $end add_client */ |
| | | |
| | | |
| | | |
| | | /* $begin check_clients */ |
| | | void NetModServerSocket::check_clients() |
| | | { |
| | |
| | | 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) { |
| | |
| | | |
| | | public: |
| | | |
| | | NetModServerSocket(int port, ShmModSocket *shm_mod_socket); |
| | | NetModServerSocket(int port, ShmModSocket *_shm_mod_socket); |
| | | void start(); |
| | | ~NetModServerSocket(); |
| | | |
| | |
| | | #include "net_mod_socket.h" |
| | | #include "socket_io.h" |
| | | #include "net_mod_socket_io.h" |
| | | |
| | | NetModSocket::NetModSocket(const char *host, int port) |
| | | { |
| | |
| | | |
| | | 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; |
| | | } |
New file |
| | |
| | | #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; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | #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 |
| | |
| | | #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(){ |
| | |
| | | |
| | | 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; |
| | |
| | | |
| | | if (strcmp("client", argv[1]) == 0) |
| | | client(); |
| | | } |
| | | } |
| | | |
| | | |
| | | |