提交 abc4e71f 创建 作者: Silas Boyd-Wickizer's avatar Silas Boyd-Wickizer

netread and netwrite implementations

上级 5df8a6fb
...@@ -65,7 +65,7 @@ filestat(struct file *f, struct stat *st) ...@@ -65,7 +65,7 @@ filestat(struct file *f, struct stat *st)
int int
fileread(struct file *f, char *addr, int n) fileread(struct file *f, char *addr, int n)
{ {
extern int netread(int, const char *, int); extern int netread(int, char *, int);
int r; int r;
if(f->readable == 0) if(f->readable == 0)
......
...@@ -268,16 +268,47 @@ netclose(int sock) ...@@ -268,16 +268,47 @@ netclose(int sock)
} }
int int
netwrite(int sock, char *buf, int len) netwrite(int sock, char *ubuf, int len)
{ {
void *kbuf;
return -1; int cc;
int r;
kbuf = kalloc();
if (kbuf == NULL)
return -1;
cc = MIN(len, PGSIZE);
if (umemcpy(kbuf, ubuf, cc)) {
kfree(kbuf);
return -1;
}
r = lwip_write(sock, kbuf, cc);
kfree(kbuf);
return r;
} }
int int
netread(int sock, const char *buf, int len) netread(int sock, char *ubuf, int len)
{ {
return -1; void *kbuf;
int cc;
int r;
kbuf = kalloc();
if (kbuf == NULL)
return -1;
cc = MIN(len, PGSIZE);
r = lwip_read(sock, kbuf, cc);
if (r < 0) {
kfree(kbuf);
return r;
}
kmemcpy(ubuf, kbuf, r);
kfree(kbuf);
return r;
} }
#else #else
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论