正在显示
1 个修改的文件
包含
72 行增加
和
0 行删除
src/server/spserver/spiochannel.hpp
0 → 100644
1 | +/* | |
2 | + * Copyright 2007 Stephen Liu | |
3 | + * For license terms, see the file COPYING along with this library. | |
4 | + */ | |
5 | + | |
6 | +#ifndef __spiochannel_hpp__ | |
7 | +#define __spiochannel_hpp__ | |
8 | + | |
9 | +class SP_Session; | |
10 | +class SP_Buffer; | |
11 | + | |
12 | +#ifdef WIN32 | |
13 | +typedef struct spwin32buffer sp_evbuffer_t; | |
14 | +#else | |
15 | +typedef struct evbuffer sp_evbuffer_t; | |
16 | +#endif | |
17 | + | |
18 | +struct iovec; | |
19 | + | |
20 | +class SP_IOChannel { | |
21 | +public: | |
22 | + virtual ~SP_IOChannel(); | |
23 | + | |
24 | + // call by an independence thread, can block | |
25 | + // return -1 : terminate session, 0 : continue | |
26 | + virtual int init( int fd ) = 0; | |
27 | + | |
28 | + // run in event-loop thread, cannot block | |
29 | + // return the number of bytes received, or -1 if an error occurred. | |
30 | + virtual int receive( SP_Session * session ) = 0; | |
31 | + | |
32 | + // run in event-loop thread, cannot block | |
33 | + // return the number of bytes sent, or -1 if an error occurred. | |
34 | + virtual int transmit( SP_Session * session ); | |
35 | + | |
36 | +protected: | |
37 | + static sp_evbuffer_t * getEvBuffer( SP_Buffer * buffer ); | |
38 | + | |
39 | + // returns the number of bytes written, or -1 if an error occurred. | |
40 | + virtual int write_vec( struct iovec * iovArray, int iovSize ) = 0; | |
41 | +}; | |
42 | + | |
43 | +class SP_IOChannelFactory { | |
44 | +public: | |
45 | + virtual ~SP_IOChannelFactory(); | |
46 | + | |
47 | + virtual SP_IOChannel * create() const = 0; | |
48 | +}; | |
49 | + | |
50 | +class SP_DefaultIOChannelFactory : public SP_IOChannelFactory { | |
51 | +public: | |
52 | + SP_DefaultIOChannelFactory(); | |
53 | + virtual ~SP_DefaultIOChannelFactory(); | |
54 | + | |
55 | + virtual SP_IOChannel * create() const; | |
56 | +}; | |
57 | + | |
58 | +class SP_DefaultIOChannel : public SP_IOChannel { | |
59 | +public: | |
60 | + SP_DefaultIOChannel(); | |
61 | + ~SP_DefaultIOChannel(); | |
62 | + | |
63 | + virtual int init( int fd ); | |
64 | + virtual int receive( SP_Session * session ); | |
65 | + | |
66 | +protected: | |
67 | + virtual int write_vec( struct iovec * iovArray, int iovSize ); | |
68 | + int mFd; | |
69 | +}; | |
70 | + | |
71 | +#endif | |
72 | + | ... | ... |
请
注册
或
登录
后发表评论