学习muduo(win平台的实现,未完成)

来源:互联网 发布:淘宝直播视频审核范本 编辑:程序博客网 时间:2024/06/04 18:53

代码在github:https://github.com/pei2017/muduo_exercise/tree/master/muduo_five/net

问题
1. __thread
__thread EventLoop* loopInThisThread = 0;用来判断当前的线程是否有已经创建了EventLoop对象。
__thread是一种线程局部存储(tls)机制,每个线程有一个该变量的实例。
windows平台下可以这样,__declspec(thread) EventLoop* loopInThisThread = 0;

2.WSAPoll相关的问题,莫名的bug?
http://blog.csdn.net/p2016/article/details/77719359

3.ssize_t
首先的话先看size_t,它是一个与机器相关的unsigned类型应为在32位系统为unsigned int,在64位系统中为 long unsigned int。
而ssize_t这个数据类型用来表示可以被执行读写操作的数据块的大小.它和size_t类似,但必需是signed.意即:它表示的是signed size_t类型的。
windows下,可以用intptr_t,其长度总是所在平台的位数,32位是int,64位是long long。

4.struct iovec和readv、writev
windows下以WSARecv和WSASend代替。
例如buffer类的readFd函数

intptr_t Buffer::readFd(int fd, int* savedErrno){    cout << "readFd() of Buffer  " << endl;    char extrabuf[65536];    WSABUF vec[2];    const size_t writable = writeableBytes();    vec[0].buf = begin() + writeIndex_;    vec[0].len = writable;    vec[1].buf = extrabuf;    vec[1].len = sizeof extrabuf;    // when there is enough space in this buffer, don't read into extrabuf.    // when extrabuf is used, we read 128k-1 bytes at most.    const int iovcnt = (writable < sizeof extrabuf) ? 2 : 1;    DWORD  n = 0;//count of received    DWORD flag = 0;    WSARecv(fd, vec, iovcnt, &n, &flag, NULL, NULL);    if (n < 0)    {        *savedErrno = errno;    }    else if (n <= DWORD(writable))    {        writeIndex_ += n;    }    else    {        writeIndex_ = buffer_.size();        append(extrabuf, n - writable);    }    return n;}

5.
windows下一些函数,inet_ntoa, inet_addr, InetPton, InetNtop.
后两个函数是新的接口,前两个也可以使用但是需要关闭编译器sdl检查。

6 还是WSAPoll
以条件变量解决 从EventLoop 的poll error;
因poll、WSAPoll的返回机制出现的问题。
http://blog.csdn.net/p2016/article/details/77842032

7 TimerQueue
http://blog.csdn.net/p2016/article/details/77809609

代码情况:
目前还剩余日志库。
另外,定时器和timestamp的实现可能会改变,其他部分代码也会修改为线程安全。
还会考虑将前置声明修改为#include。https://www.zhihu.com/question/63201378