Git Product home page Git Product logo

win_iocp_server's Introduction

win_iocp_server

windows iocp实现的tcp server,基于C++ 03标准,使用vs2008开发,使用了tr1库中的shared_ptr、bind和function。

本工程,主要演示了TCP server创建服务,接受请求,触发回调,及收发数据的处理。 主要解决了,socket全双工时,能够根据OVERLAPPED指针,判断出是是收数据事件还是发数据事件,并且能够找到对应的session对象。

核心技术

  • OVERLAPPED的继承,GetQueuedCompletionStatus有事件响应时,获取对应session对象
class io_context : public OVERLAPPED {
...
private:
  session *parent_;
}
  • session用于封装套接字和对应相关联的OVERLAPPED上下文,这样套接字可以同时post 收发事件
class session : public std::tr1::enable_shared_from_this<session> {
...
private:
  SOCKET st_;
  long send_len_; //总共发送
  long recv_len_; //总共接收
  io_context *array_ctx_[2]; //接收和发送的OVERLAPPED对象
};

以上使用了两个不同的OVERLAPPED对象,创建两个的目的主要解决,同时提交收发事件时无法通过session对象的 enum dwIOType{ IO_RECV, IO_SEND}类型,判断是否为接收或发送事件。

后续

基于此server 实现https server

win_iocp_server's People

Contributors

muxq avatar

Stargazers

 avatar  avatar

Watchers

 avatar

win_iocp_server's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.