SWC-DB  v0.5.12 C++ documentations
SWC-DB© (Super Wide Column Database) - High Performance Scalable Database (https://github.com/kashirin-alex/swc-db)
Create.h
Go to the documentation of this file.
1 /*
2  * SWC-DB© Copyright since 2019 Alex Kashirin <kashirin.alex@gmail.com>
3  * License details at <https://github.com/kashirin-alex/swc-db/#license>
4  */
5 
6 
7 #ifndef swcdb_fsbroker_handlers_Create_h
8 #define swcdb_fsbroker_handlers_Create_h
9 
12 
13 
14 namespace SWC { namespace Comm { namespace Protocol {
15 namespace FsBroker { namespace Handler {
16 
17 
18 void create(const ConnHandlerPtr& conn, const Event::Ptr& ev) {
19 
20  int err = Error::OK;
21  int32_t fd = -1;
22  try {
23 
24  const uint8_t *ptr = ev->data.base;
25  size_t remain = ev->data.size;
26 
27  Params::CreateReq params;
28  params.decode(&ptr, &remain);
29 
30  auto smartfd = FS::SmartFd::make_ptr(
31  std::move(params.fname), params.flags);
32 
33  Env::FsInterface::fs()->create(err, smartfd, params.replication);
34 
35  if(smartfd->valid())
36  fd = Env::FsBroker::fds().add(smartfd);
37 
38  } catch(...) {
41  err = e.code();
42  }
43 
44  auto cbp = Buffers::make(ev, Params::OpenRsp(fd), 4);
45  cbp->append_i32(err);
46  conn->send_response(cbp);
47 
48 }
49 
50 
51 }}}}}
52 
53 #endif // swcdb_fsbroker_handlers_Create_h
SWC::Error::Exception::code
constexpr SWC_CAN_INLINE int code() const noexcept
Definition: Exception.h:51
SWC::Comm::Protocol::FsBroker::Params::OpenRsp
Definition: Open.h:45
SWC_LOG_OSTREAM
#define SWC_LOG_OSTREAM
Definition: Logger.h:44
SWC_LOG_OUT
#define SWC_LOG_OUT(pr, _code_)
Definition: Logger.h:178
SWC::FS::SmartFd::make_ptr
static SWC_CAN_INLINE Ptr make_ptr(const std::string &filepath, uint32_t flags, int32_t fd=-1, uint64_t pos=0)
Definition: SmartFd.h:40
SWC::Comm::Protocol::FsBroker::Params::CreateReq
Definition: Create.h:17
SWC::Comm::Protocol::FsBroker::Params::CreateReq::flags
uint32_t flags
Definition: Create.h:32
SWC::Comm::Protocol::FsBroker::Params::CreateReq::fname
std::string fname
Definition: Create.h:31
SWC::Error::OK
@ OK
Definition: Error.h:45
SWC::Comm::Protocol::FsBroker::Handler::create
void create(const ConnHandlerPtr &conn, const Event::Ptr &ev)
Definition: Create.h:18
SWC_CURRENT_EXCEPTION
#define SWC_CURRENT_EXCEPTION(_msg_)
Definition: Exception.h:119
SWC
The SWC-DB C++ namespace 'SWC'.
Definition: main.cc:12
SWC::Env::FsInterface::fs
static SWC_CAN_INLINE FS::FileSystem::Ptr & fs() noexcept
Definition: Interface.h:155
Create.h
SWC::LOG_ERROR
@ LOG_ERROR
Definition: Logger.h:32
SWC::Comm::ConnHandlerPtr
std::shared_ptr< ConnHandler > ConnHandlerPtr
Definition: AppContext.h:17
SWC::Comm::Buffers::make
static SWC_CAN_INLINE Ptr make(uint32_t reserve=0)
Definition: Buffers.h:27
SWC::Comm::Serializable::decode
void decode(const uint8_t **bufp, size_t *remainp)
Definition: Serializable.h:59
SWC::Comm::Protocol::FsBroker::Params::CreateReq::replication
uint8_t replication
Definition: Create.h:33
SWC::Comm::Event::Ptr
std::shared_ptr< Event > Ptr
Definition: Event.h:33
SWC::Env::FsBroker::fds
static SWC_CAN_INLINE SWC::FsBroker::Fds & fds() noexcept
Definition: FsBrokerEnv.h:70
Open.h
SWC::FsBroker::Fds::add
int32_t add(const FS::SmartFd::Ptr &smartfd)
Definition: FsBrokerEnv.h:187
SWC::Error::Exception
Definition: Exception.h:21