/* * predixy - A high performance and full features proxy for redis. * Copyright (C) 2017 Joyield, Inc. * All rights reserved. */ #ifndef _PREDIXY_CONNECT_CONNECTION_H_ #define _PREDIXY_CONNECT_CONNECTION_H_ #include "Predixy.h" #include "ConnectSocket.h" #include "Connection.h" #include "Request.h" #include "ResponseParser.h" class ConnectConnection : public ConnectSocket, public Connection, public ListNode, public DequeNode { public: typedef ConnectConnection Value; typedef ListNode ListNodeType; typedef DequeNode DequeNodeType; public: ConnectConnection(Server* s, bool shared); ~ConnectConnection(); bool writeEvent(Handler* h); void readEvent(Handler* h); void send(Handler* h, Request* req); void close(Handler* h); Server* server() const { return mServ; } bool isShared() const { return mShared; } bool isAuth() const { return mAuthed; } void setAuth(bool v) { mAuthed = v; } bool readonly() const { return mReadonly; } void setReadonly(bool v) { mReadonly = v; } void attachAcceptConnection(AcceptConnection* c) { mAcceptConnection = c; } void detachAcceptConnection() { mAcceptConnection = nullptr; } AcceptConnection* acceptConnection() const { return mAcceptConnection; } int pendRequestCount() const { return mSendRequests.size() + mSentRequests.size(); } private: void parse(Handler* h, Buffer* buf, int pos); void handleResponse(Handler* h); void write(); int fill(Handler* h, IOVec* bufs, int len); bool write(Handler* h, IOVec* bufs, int len); private: Server* mServ; AcceptConnection* mAcceptConnection; ResponseParser mParser; SendRequestList mSendRequests; SendRequestList mSentRequests; bool mShared; bool mAuthed; bool mReadonly; }; typedef List ConnectConnectionList; typedef Deque ConnectConnectionDeque; typedef Alloc ConnectConnectionAlloc; #endif