aboutsummaryrefslogtreecommitdiff
path: root/src/main.h
diff options
context:
space:
mode:
authorEric Lombrozo <elombrozo@gmail.com>2013-06-23 17:35:01 -0700
committerEric Lombrozo <elombrozo@gmail.com>2013-06-23 19:58:23 -0700
commita6dba0fdb281ee99e6814ad64c1c4d3032347816 (patch)
treecd0b5e67aea0f2b47ff3faf7719328c1680bbe4c /src/main.h
parentfd967fed89a294622f24c8e97c0ed23afb969edd (diff)
Moved CBlock::WriteToDisk out of CBlock to inline function WriteBlockToDisk in main.h
Diffstat (limited to 'src/main.h')
-rw-r--r--src/main.h51
1 files changed, 26 insertions, 25 deletions
diff --git a/src/main.h b/src/main.h
index c5e5f2bfe6..bda775e843 100644
--- a/src/main.h
+++ b/src/main.h
@@ -682,31 +682,6 @@ public:
return hash;
}
- bool WriteToDisk(CDiskBlockPos &pos)
- {
- // Open history file to append
- CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
- if (!fileout)
- return error("CBlock::WriteToDisk() : OpenBlockFile failed");
-
- // Write index header
- unsigned int nSize = fileout.GetSerializeSize(*this);
- fileout << FLATDATA(Params().MessageStart()) << nSize;
-
- // Write block
- long fileOutPos = ftell(fileout);
- if (fileOutPos < 0)
- return error("CBlock::WriteToDisk() : ftell failed");
- pos.nPos = (unsigned int)fileOutPos;
- fileout << *this;
-
- // Flush stdio buffers and commit to disk before returning
- fflush(fileout);
- if (!IsInitialBlockDownload())
- FileCommit(fileout);
-
- return true;
- }
bool ReadFromDisk(const CDiskBlockPos &pos)
{
@@ -779,6 +754,32 @@ public:
};
+/** Functions for disk access for blocks */
+inline bool WriteBlockToDisk(CBlock& block, CDiskBlockPos& pos)
+{
+ // Open history file to append
+ CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
+ if (!fileout)
+ return error("WriteBlockToDisk() : OpenBlockFile failed");
+
+ // Write index header
+ unsigned int nSize = fileout.GetSerializeSize(block);
+ fileout << FLATDATA(Params().MessageStart()) << nSize;
+
+ // Write block
+ long fileOutPos = ftell(fileout);
+ if (fileOutPos < 0)
+ return error("WriteBlockToDisk() : ftell failed");
+ pos.nPos = (unsigned int)fileOutPos;
+ fileout << block;
+
+ // Flush stdio buffers and commit to disk before returning
+ fflush(fileout);
+ if (!IsInitialBlockDownload())
+ FileCommit(fileout);
+
+ return true;
+}