当前位置: 首页 > news >正文

老河口做网站百度贴吧广告投放

老河口做网站,百度贴吧广告投放,企业网站建设方案撰写,网站图标做多大好零拷贝技术介绍&#xff1a;史上最全零拷贝总结-CSDN博客 这是一个简单的基于epoll的Linux TCP代理程序&#xff0c;通过匿名管道和零拷贝技术的splice函数&#xff0c;将两个TCP端口相互连接&#xff0c;并转发数据。 #define _GNU_SOURCE 1 #include <sys/socket.h> …

零拷贝技术介绍:史上最全零拷贝总结-CSDN博客

这是一个简单的基于epoll的Linux TCP代理程序,通过匿名管道和零拷贝技术的splice函数,将两个TCP端口相互连接,并转发数据。

#define _GNU_SOURCE 1
#include <sys/socket.h>
#include <sys/epoll.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdbool.h>
#include <errno.h>
#include <assert.h>
#include <time.h>
#include "list.h"#define err(x) perror(x), exit(1)
#define NEW(x) ((x) = xmalloc(sizeof(*(x))))
#define MAX(a,b) ((a) > (b) ? (a) : (b))int connection_timeout = 5; /* XXX configurable */void oom(void)
{fprintf(stderr, "Out of memory\n");exit(1);
}void *xmalloc(size_t size)
{void *p = calloc(size, 1);if (!p)oom();return p;
}void *xrealloc(void *old, size_t size)
{void *p = realloc(old, size);if (!p)oom();return p;
}struct addrinfo *resolve(char *name, char *port, int flags)
{int ret;struct addrinfo *adr;struct addrinfo hint = { .ai_flags = flags };ret = getaddrinfo(name, port, &hint, &adr);if (ret) {fprintf(stderr, "proxy: Cannot resolve %s %s: %s\n",name, port, gai_strerror(ret));exit(1);}return adr;
}void setnonblock(int fd, int *cache)
{int flags;if (!cache || *cache == -1) {flags = fcntl(fd, F_GETFL, 0);if (cache)*cache = flags;} elseflags = *cache;fcntl(fd, F_SETFL, flags|O_NONBLOCK);
}struct buffer {int pipe[2];int bytes;
};struct conn {struct conn *other;int fd;struct buffer buf;time_t expire;struct list_head expire_node;
};LIST_HEAD(expire_list);#define MIN_EVENTS 32
struct epoll_event *events;
int num_events, max_events;int epoll_add(int efd, int fd, int revents, void *conn)
{struct epoll_event ev = { .events = revents, .data.ptr = conn };if (++num_events >= max_events) {max_events = MAX(max_events * 2, MIN_EVENTS);events = xrealloc(events, sizeof(struct epoll_event) * max_events);}return epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
}int epoll_del(int efd, int fd)
{num_events--;assert(num_events >= 0);return epoll_ctl(efd, EPOLL_CTL_DEL, fd, (void *)1L);
}/* Create buffer between two connections */
struct buffer *newbuffer(struct buffer *buf)
{if (pipe2(buf->pipe, O_NONBLOCK) < 0) {perror("pipe");return NULL;}return buf;
}void delbuffer(struct buffer *buf)
{close(buf->pipe[0]);close(buf->pipe[1]);
}void delconn(int efd, struct conn *conn)
{list_del(&conn->expire_node);delbuffer(&conn->buf);epoll_del(efd, conn->fd);close(conn->fd);free(conn);
}struct conn *newconn(int efd, int fd, time_t now)
{struct conn *conn;NEW(conn);conn->fd = fd;if (!newbuffer(&conn->buf)) {delconn(efd, conn);return NULL;}if (epoll_add(efd, fd, EPOLLIN|EPOLLOUT|EPOLLET, conn) < 0) {perror("epoll");delconn(efd, conn);return NULL;}conn->expire = now + connection_timeout;list_add_tail(&conn->expire_node, &expire_list);return conn;
}/* Process incoming connection. */
void new_request(int efd, int lfd, int *cache, time_t now)
{int newsk = accept(lfd, NULL, NULL);if (newsk < 0) {perror("accept");return;}// xxx logsetnonblock(newsk, cache);newconn(efd, newsk, now);
}/* Open outgoing connection */
struct conn *
openconn(int efd, struct addrinfo *host, int *cache, struct conn *other,time_t now)
{int outfd = socket(host->ai_family, SOCK_STREAM, 0);if (outfd < 0)return NULL;setnonblock(outfd, cache);int n = connect(outfd, host->ai_addr, host->ai_addrlen);if (n < 0 && errno != EINPROGRESS) {perror("connect");close(outfd);return NULL;}struct conn *conn = newconn(efd, outfd, now);if (conn) {conn->other = other;other->other = conn;}return conn;
}#define BUFSZ 16384 /* XXX *//* Move from socket to pipe */
bool move_data_in(int srcfd, struct buffer *buf)
{for (;;) {	int n = splice(srcfd, NULL, buf->pipe[1], NULL, BUFSZ, SPLICE_F_NONBLOCK|SPLICE_F_MOVE);if (n > 0)buf->bytes += n;if (n == 0)return false;if (n < 0) {if (errno == EAGAIN || errno == EWOULDBLOCK)return true;return false;}}return true;
}/* From pipe to socket */
bool move_data_out(struct buffer *buf, int dstfd)
{ while (buf->bytes > 0) {int bytes = buf->bytes;if (bytes > BUFSZ)bytes = BUFSZ;int n = splice(buf->pipe[0], NULL, dstfd, NULL,bytes, SPLICE_F_NONBLOCK|SPLICE_F_MOVE);if (n == 0)break;if (n < 0) {if (errno == EAGAIN || errno == EWOULDBLOCK)break;return false;}buf->bytes -= n;}/* bytes > 0, add dst to epoll set *//* else remove if it was added */return true;
}void closeconn(int efd, struct conn *conn)
{if (conn->other)delconn(efd, conn->other);delconn(efd, conn);		
}int expire_connections(int efd, time_t now)
{struct conn *conn, *tmp;list_for_each_entry_safe (conn, tmp, &expire_list, expire_node) {if (conn->expire > now)return (conn->expire - now) * 1000;closeconn(efd, conn);}return -1;
}void touch_conn(struct conn *conn, time_t now)
{conn->expire = now + connection_timeout;list_del(&conn->expire_node);list_add_tail(&conn->expire_node, &expire_list);
}int listen_socket(int efd, char *lname, char *port)
{struct addrinfo *laddr = resolve(lname, port, AI_PASSIVE);int lfd = socket(laddr->ai_family, SOCK_STREAM, 0);if (lfd < 0) err("socket");int opt = 1;if (setsockopt(lfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int)) < 0) err("SO_REUSEADDR");if (bind(lfd, laddr->ai_addr, laddr->ai_addrlen) < 0) err("bind");if (listen(lfd, 20) < 0) err("listen");setnonblock(lfd, NULL);freeaddrinfo(laddr);if (epoll_add(efd, lfd, EPOLLIN, NULL) < 0) err("epoll add listen fd");return lfd;
}int main(int ac, char **av)
{if (ac != 4 && ac != 5) {fprintf(stderr,"Usage: proxy inport outhost outport [listenaddr]\n");exit(1);}struct addrinfo *outhost = resolve(av[2], av[3], 0);int efd = epoll_create(10);if (efd < 0) err("epoll_create");int lfd = listen_socket(efd, av[4] ? av[4] : "0.0.0.0", av[1]);int cache_in = -1, cache_out = -1;	int timeo = -1;for (;;) {int nfds = epoll_wait(efd, events, num_events, timeo);if (nfds < 0) {perror("epoll");continue;}time_t now = time(NULL);int i;for (i = 0; i < nfds; i++) { struct epoll_event *ev = &events[i];struct conn *conn = ev->data.ptr;/* listen socket */if (conn == NULL) {if (ev->events & EPOLLIN)new_request(efd, lfd, &cache_in, now);continue;} if (ev->events & (EPOLLERR|EPOLLHUP)) {closeconn(efd, conn);continue;}struct conn *other = conn->other;/* No attempt for partial close right now */if (ev->events & EPOLLIN) {touch_conn(conn, now);if (!other)other = openconn(efd, outhost, &cache_out,conn, now);bool in = move_data_in(conn->fd, &conn->buf);bool out = move_data_out(&conn->buf, other->fd);if (!in || !out) { closeconn(efd, conn);continue;}touch_conn(other, now);}	if ((ev->events & EPOLLOUT) && other) {if (!move_data_out(&other->buf, conn->fd))delconn(efd, conn);elsetouch_conn(conn, now);/* When the pipe filled up could havelost input events.  Unfortunatelysplice doesn't tell us which endwas responsible for 0, so have to askexplicitely. */int len = 0;if (ioctl(other->fd, FIONREAD, &len) < 0)perror("ioctl");if (len > 0) {if (!move_data_in(other->fd, &other->buf))closeconn(efd, other);}}}	timeo = expire_connections(efd, now);}return 0;
}

文章转载自:
http://caprine.qkqn.cn
http://torus.qkqn.cn
http://slv.qkqn.cn
http://spirillum.qkqn.cn
http://imitation.qkqn.cn
http://specification.qkqn.cn
http://muggler.qkqn.cn
http://klutz.qkqn.cn
http://plasticiser.qkqn.cn
http://petrograd.qkqn.cn
http://virile.qkqn.cn
http://spiciness.qkqn.cn
http://enchondrosis.qkqn.cn
http://dissipator.qkqn.cn
http://yard.qkqn.cn
http://crossly.qkqn.cn
http://suzuribako.qkqn.cn
http://cauri.qkqn.cn
http://thuggism.qkqn.cn
http://breadthwise.qkqn.cn
http://ermentrude.qkqn.cn
http://quintessence.qkqn.cn
http://proportionately.qkqn.cn
http://upwards.qkqn.cn
http://aborticide.qkqn.cn
http://arietta.qkqn.cn
http://oxidizer.qkqn.cn
http://erythrophobia.qkqn.cn
http://chromoplast.qkqn.cn
http://nonart.qkqn.cn
http://nobbler.qkqn.cn
http://inflorescence.qkqn.cn
http://yam.qkqn.cn
http://rcmp.qkqn.cn
http://riprap.qkqn.cn
http://virelay.qkqn.cn
http://denumerable.qkqn.cn
http://zamboni.qkqn.cn
http://cot.qkqn.cn
http://somewhy.qkqn.cn
http://codline.qkqn.cn
http://absolutization.qkqn.cn
http://rondure.qkqn.cn
http://sculptress.qkqn.cn
http://yen.qkqn.cn
http://chiseler.qkqn.cn
http://psychosynthesis.qkqn.cn
http://violetta.qkqn.cn
http://rootlet.qkqn.cn
http://pottage.qkqn.cn
http://diptera.qkqn.cn
http://hesiflation.qkqn.cn
http://balalaika.qkqn.cn
http://piggish.qkqn.cn
http://realizing.qkqn.cn
http://aggression.qkqn.cn
http://merovingian.qkqn.cn
http://lustreware.qkqn.cn
http://sonlike.qkqn.cn
http://superfecta.qkqn.cn
http://outfly.qkqn.cn
http://epiphenomenalism.qkqn.cn
http://ait.qkqn.cn
http://petting.qkqn.cn
http://caraway.qkqn.cn
http://ylem.qkqn.cn
http://irides.qkqn.cn
http://atreus.qkqn.cn
http://powerpc.qkqn.cn
http://tdb.qkqn.cn
http://panbroil.qkqn.cn
http://holohedron.qkqn.cn
http://transfer.qkqn.cn
http://vowel.qkqn.cn
http://theodicean.qkqn.cn
http://paring.qkqn.cn
http://diagnostical.qkqn.cn
http://photometry.qkqn.cn
http://glissando.qkqn.cn
http://shogun.qkqn.cn
http://amalgamate.qkqn.cn
http://heterogonous.qkqn.cn
http://merle.qkqn.cn
http://materialman.qkqn.cn
http://definitive.qkqn.cn
http://slipware.qkqn.cn
http://opalescent.qkqn.cn
http://apomixis.qkqn.cn
http://comedown.qkqn.cn
http://unassailable.qkqn.cn
http://jubal.qkqn.cn
http://uncork.qkqn.cn
http://terrorist.qkqn.cn
http://summerly.qkqn.cn
http://tablemate.qkqn.cn
http://catechumen.qkqn.cn
http://goniometry.qkqn.cn
http://antilithic.qkqn.cn
http://stingaree.qkqn.cn
http://toolmaking.qkqn.cn
http://www.dt0577.cn/news/62855.html

相关文章:

  • 网站开发实训要求手机网站制作软件
  • 武汉网站建设服务平台推广是做什么的
  • 软件网站开发搜索引擎推广步骤
  • 做网站上是外部连接怎么改友情链接交易
  • 东莞人才市场现场招聘会地址seo81
  • 懂福溶州做戒网站广州seo搜索
  • css网站模板下载网站如何优化推广
  • 校园互动平台网站建设2023年的新闻时事热点论文
  • wordpress怎么登陆地址seo职位要求
  • now9999网站提示建设中深圳seo优化排名优化
  • 企业网站建设费用会计分录微营销推广软件
  • 福彩网站开发网站网络推广运营
  • 嘉定网站建设哪家便宜it行业培训机构哪个好
  • 上海做网站谁好网络优化大师
  • 鄂州网站建设营业推广怎么写
  • 盐城市城乡建设局网站做网站用什么编程软件
  • 好123上网从这里开始360优化大师安卓手机版下载安装
  • 有做公司网站的吗seo如何优化图片
  • 网站建设的基本费用中国培训网官网
  • 成都网站建设公uc推广登录入口
  • 湖北企业响应式网站建设价位如何推广网站
  • 肇庆做网站设计5188关键词挖掘
  • 网站扁平化廊坊seo外包
  • 网站开发常用单词百度知道首页网
  • 西安市建设和住房保障局网站免费外链发布平台
  • 网页设计制作报价郑州seo代理外包公司
  • qq网站推广代码职业培训热门行业
  • 雄安做网站要多少钱seo培训一对一
  • 湘潭做网站 都来磐石网络友情链接实例
  • 网站备案手续企业推广策略