ACE Source Example - IPC SAP

xiaoxiao2021-03-06  180

The following example has been released in "ACE Programmers Guide". These code are from hughes network systems. If you have any questions, you can send an email to umar syyid

Or exchange hxhforwork@hotmail.com :)

/ This example is from the ACE Programmers Guide Chapter:.. "IPC SAP" (Interprocess Communication Mechanisms in ACE) For details please see the guide at http://www.cs.wustl.edu/~schmidt/ACE.html AUTHOR : Umar syyid (usyiid@hns.com) And Ambreen ilyas (Ambreen@bitsmart.com) /

// EXAMPLE 1 #include "ACE / SOCK_ACCEPTOR.H" #include "ace / sock_stream.h" #define size_data 18 #define size_buf 1024

Class Server {

Public: Server (int port): server_addr_ (port), peer_acceptor_ (server_addr _) {data_buf_ = new char [size_buf];

// Handle the connection once it has been established. // Here the connection is handled by reading SIZE_DATA amount of data // from the remote and then closing the connection // stream down. Int handle_connection () {// Read data from client IF (new_stream_.recv_n (data_buf_, size_data, 0) == - 1) ACE_ERROR ((LM_ERROR, "% P / N", "ERROR IN RECV"));

ACE_DEBUG ((LM_Debug, "Server Recieved% S / N", DATA_BUF_)); // Close New Endpoint IF (new_stream_.close () == -1) ACE_ERROR ((LM_ERROR, "% P / N", "close" )); return 0;} // Use the acceptor component peer_acceptor_ to accept the connection // into the underlying stream new_stream_ After the connection has been // established call the handle_connenction () method int accept_connections () {if (peer_acceptor_... GET_LOCAL_ADDR (Server_ADDR_) == -1) ACE_ERROR_RETURN ((LM_ERROR, "% P / N", "Error IN GET_LOCAL_ADDR"), 1);

ACE_DEBUG ((LM_Debug, "Starting Server AT Port% D / N", Server_addr_.get_port_number ()));

// Performs the iterative server activities while (1) {ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);. If (peer_acceptor_.accept (new_stream_, & client_addr_, & timeout) == -1) {ACE_ERROR ((LM_ERROR, "% p / n", " accept ")); continue;} else ACE_DEBUG ((LM_DEBUG," Connection established with remote% s:% d / n ", client_addr_.get_host_name (), client_addr_.get_port_number ())); // Handle the connection handle_connection () ;}} Private: char * data_buf_; audord_; ace_ines_addr client_addr_; ace_sock_acceptor peer_acceptor_; ace_sock_stream new_stream_; ace_handle newhandle;};

INT Main (int Argc, char * argv []) {if (argc <2) {ace_ERROR ((lm_error, "usage EGX

"));

ACE_OS :: EXIT (1);

}

Server Server (ACE_OS :: ATOI (Argv [1]));

Server.accept_connections ();

}

转载请注明原文地址:https://www.9cbs.com/read-128085.html

New Post(0)