Skip to content

Commit

Permalink
add serial code
Browse files Browse the repository at this point in the history
  • Loading branch information
gombiuda committed Feb 8, 2014
1 parent 2158cb6 commit 62f78b3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
29 changes: 25 additions & 4 deletions connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Connection::Connection(int fd_) : fd(fd_) {
out = new BipBuffer(BUFFER_SIZE);
}

void Connection::handle(RingBuffer<Order> *ring) {
void Connection::handle(RingBuffer<Order> *ring, Train *train) {
char *index_in, *index_out;
int n;
Order *order;
Expand Down Expand Up @@ -48,13 +48,34 @@ void Connection::handle(RingBuffer<Order> *ring) {
}
order->connection = this;
/* // test-start */
/* index_out = out->reserve(end - start + 1); */
/* switch (order->operation) { */
/* case 0x01: */
/* train->query(order); */
/* break; */
/* case 0x02: */
/* train->book(order); */
/* break; */
/* case 0x03: */
/* train->check(order); */
/* break; */
/* case 0x04: */
/* train->refund(order); */
/* break; */
/* default: */
/* cout << "unknown operation " << hex << order->operation << endl; */
/* exit(1); */
/* } */
/* if (order->dump() == -1) { */
/* cout << "order dump fail" << endl; */
/* exit(1); */
/* } */
/* index_out = out->reserve(order->rsize); */
/* if (index_out == nullptr) { */
/* perror("in reserve error"); */
/* exit(1); */
/* } */
/* memcpy(index_out, index_in + start, end - start + 1); */
/* out->commit(end - start + 1); */
/* memcpy(index_out, order->raw, order->rsize); */
/* out->commit(order->rsize); */
/* // test-end */
in->release(end);
count++;
Expand Down
3 changes: 2 additions & 1 deletion connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
#include "bipbuffer.h"
#include "ringbuffer.h"
#include "order.h"
#include "train.h"

using namespace std;

class Connection {
public:
Connection(int fd);
BipBuffer *in, *out;
void handle(RingBuffer<Order> *ring);
void handle(RingBuffer<Order> *ring, Train *train);
void flush();
void close_connection();
private:
Expand Down
2 changes: 1 addition & 1 deletion server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Server::receive_data(int fd) {
exit(1);
}
Connection *connection = pair->second;
connection->handle(ring);
connection->handle(ring, train);
}

void Server::handle_orders() {
Expand Down

0 comments on commit 62f78b3

Please sign in to comment.