- 论坛徽章:
- 2
|
原帖由 yhb04 于 2009-3-27 22:12 发表 ![]()
呵呵,其实我的代码还有问题,具体的接口中应该包括C++中类似this指针。
你的意思是 :
struct file_ops {
int (*read)(struct file*, char* buff, int count);
int (*write)(struct file*, char* buff, nt count);
/* ... */
};
这样?
给客户端提供的是 :
int read( struct file* f, char* buf, int count) {
return f->op->read( f, buf, count ); // 这一坨东西, 不应该交给用户去写吧。
}
这样?
我觉得你在335楼的设计更好一些。
struct file_ops {
int (*read)(int fd, char* buff, int count);
int (*write)(int fd, char* buff, nt count);
/* ... */
};
int read( struct file* f, char* buf, int count) {
return f->op->read( f->fd, buf, count );
}
这样, 实现 read, write 的时候, 将不依赖struct file这个东西。 int fd才是最抽象的handle。
[ 本帖最后由 OwnWaterloo 于 2009-3-27 22:27 编辑 ] |
|