mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:12:43 +00:00 
			
		
		
		
	 b91c49364d
			
		
	
	
		b91c49364d
		
	
	
	
	
		
			
			This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
		
			
				
	
	
		
			49 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			49 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/String.h>
 | |
| #include <AK/StringView.h>
 | |
| #include <AK/Types.h>
 | |
| #include <LibCore/Notifier.h>
 | |
| #include <LibCore/TCPSocket.h>
 | |
| 
 | |
| #include "Command.h"
 | |
| #include "Parser.h"
 | |
| 
 | |
| class Client : public RefCounted<Client> {
 | |
| public:
 | |
|     static NonnullRefPtr<Client> create(int id, RefPtr<Core::TCPSocket> socket, int ptm_fd)
 | |
|     {
 | |
|         return adopt_ref(*new Client(id, move(socket), ptm_fd));
 | |
|     }
 | |
| 
 | |
|     Function<void()> on_exit;
 | |
| 
 | |
| protected:
 | |
|     Client(int id, RefPtr<Core::TCPSocket> socket, int ptm_fd);
 | |
| 
 | |
|     void drain_socket();
 | |
|     void drain_pty();
 | |
|     void handle_data(const StringView&);
 | |
|     void handle_command(const Command& command);
 | |
|     void handle_error();
 | |
|     void send_data(StringView str);
 | |
|     void send_command(Command command);
 | |
|     void send_commands(Vector<Command> commands);
 | |
|     void quit();
 | |
| 
 | |
| private:
 | |
|     // client id
 | |
|     int m_id { 0 };
 | |
|     // client resources
 | |
|     RefPtr<Core::TCPSocket> m_socket;
 | |
|     Parser m_parser;
 | |
|     // pty resources
 | |
|     int m_ptm_fd { -1 };
 | |
|     RefPtr<Core::Notifier> m_ptm_notifier;
 | |
| };
 |