1 #include "scd_command_writer.h"
5 #include "scd_logging.h"
8 scd_command_writer::scd_command_writer():
9 _is_writing(false), _remaining(0) {}
12 scd_command_writer::~scd_command_writer()
14 std::list<scd_command*>::iterator iter;
15 for ( iter = _commands.begin(); iter != _commands.end(); iter++)
20 void scd_command_writer::set_socket(scd_socket& sock) { _socket = &sock; }
23 bool scd_command_writer::is_writing() const { return _is_writing; }
26 bool scd_command_writer::queue_command(scd_command* cmd)
28 if (cmd->_msglen <= SCD_CM_MAXLEN)
30 _commands.push_back(cmd);
36 scd_warn("command too long");
42 void scd_command_writer::write()
47 finishedmsg = _send_cmd();
54 inline bool scd_command_writer::_send_cmd()
61 /* fetch next command */
62 scd_command* cmd = _commands.front();
63 _commands.pop_front();
65 // store header to buffer
66 uint16_t* intbuf = reinterpret_cast<uint16_t*>(_buf);
67 intbuf[0] = htons(cmd->_type);
68 intbuf[1] = htons(cmd->_subtype);
69 intbuf[2] = htons(cmd->_msglen);
71 // store message to buffer
72 memcpy(_buf + SCD_CM_HEADER, cmd->_msg, cmd->_msglen);
74 _remaining = SCD_CM_HEADER + cmd->_msglen;
79 size_t sent = _socket->send(_buf + _off, _remaining);
86 if (_commands.empty())