-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNDisk.cpp
More file actions
57 lines (45 loc) · 981 Bytes
/
NDisk.cpp
File metadata and controls
57 lines (45 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/** @file NDisk.cpp
*
* Network Disk structure derived from Disk. Uses RPC to communicate to
* the server.
*
* @author Copyright Aniesh Chawla, Sept 2006
**/
#include "NDisk.h"
#include <iostream>
NDisk::NDisk()
{
proxy.connect("localhost", NDISK_DEFAULT_PORT);
}
NDisk::NDisk(const char *host, int port)
{
proxy.connect(host, port);
}
NDisk::~NDisk()
{
proxy.disconnect();
}
int NDisk::num_blocks() const
{
char buf[NDISK_BLOCK_SIZE];
proxy.call("NUMB", 0, buf);
// Get num blocks from packet data
return ston(buf);
}
int NDisk::block_size() const
{
return NDISK_BLOCK_SIZE;
}
int NDisk::format(int num_blocks)
{
return proxy.call("FRMT", num_blocks, NULL);
}
int NDisk::read(int block_num, char *buf) const
{
return proxy.call("READ", block_num, buf);
}
int NDisk::write(int block_num, const char *buf)
{
//std::cout<<"writing "<<buf<<" at "<<block_num<<std::endl;
return proxy.call("WRTE", block_num, (char*)buf);
}