|
#include "ace/Event_Handler.h"
#include "ace/Proactor.h"
#include "ace/SSL/SSL_SOCK_Acceptor.h"
#include "ace/Thread_Manager.h"
#include "ace/INET_Addr.h"
#include "ace/SSL/SSL_Asynch_Stream.h"
class Server_Handler : public ACE_Handler
{
public:
Server_Handler ()
: msgs_rcvd_ (0),
stream_ (NULL/*ACE_SSL_Asynch_Stream::ST_SERVER*/),
block_ (1024) {}
~Server_Handler ();
int open (ACE_HANDLE);
private:
virtual void handle_read_stream (const ACE_Asynch_Read_Stream::Result &result);
private:
size_t msgs_rcvd_;
ACE_SSL_Asynch_Stream *stream_;
ACE_Message_Block block_;
};
static size_t cli_req_no = 10;
Server_Handler::~Server_Handler ()
{
if (this->stream_->handle() != ACE_INVALID_HANDLE)
{
if (this->msgs_rcvd_ != cli_req_no)
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) Server handle %d received %d messages; ")
ACE_TEXT ("expected %d\n"),
this->stream_->handle (),
this->msgs_rcvd_,
cli_req_no));
else
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Server handle %d received %d messages; ")
ACE_TEXT ("closing connection\n"),
this->stream_->handle (),
cli_req_no));
}
this->stream_->close ();
}
int
Server_Handler::open (ACE_HANDLE handle)
{
if (this->stream_->open (*this, handle) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) Server_Handler: %p\n"),
ACE_TEXT ("open")),
-1);
if (this->stream_->read (this->block_, this->block_.space () - 1) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) Server_Handler: %p\n"),
ACE_TEXT ("read")),
-1);
return 0;
}
void
Server_Handler::handle_read_stream(const ACE_Asynch_Read_Stream::Result &result)
{
#if 0
if (!result.success ())
{
errno = result.error ();
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) Server handle %d: %p\n"),
this->stream_.handle (),
ACE_TEXT ("read")));
delete this;
return;
}
if (result.bytes_transferred () == 0)
{
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("(%t) Server handle %d closed by peer\n"),
this->stream_.handle ()));
delete this;
return;
}
// Scan through the received data for the expected string. There may be
// multiples and/or partials. Count up how many arrive before the connection
// is closed.
// The read operation left one byte space at the end so we can insert a
// nul terminator to ease scanning.
ACE_Message_Block &b = result.message_block ();
*(b.wr_ptr ()) = '\0';
size_t test_string_len = ACE_OS::strlen (test_string);
while (b.length () >= test_string_len)
{
if (0 != ACE_OS::strncmp (b.rd_ptr (), test_string, test_string_len))
ACE_ERROR_BREAK ((LM_ERROR,
ACE_TEXT ("(%t) Read string: %C; expected: %C\n"),
b.rd_ptr (),
test_string));
b.rd_ptr (test_string_len);
}
b.crunch ();
if (this->stream_.read (b, b.space () - 1) == -1)
{
ACE_ERROR ((LM_ERROR,
ACE_TEXT ("(%t) Server_Handler: %p\n"),
ACE_TEXT ("read")));
delete this;
}
return;
#endif
}
class Server_Acceptor : public ACE_Event_Handler
{
public:
int open (const ACE_INET_Addr &listen_addr);
virtual int handle_input (ACE_HANDLE fd = ACE_INVALID_HANDLE);
virtual int handle_close (ACE_HANDLE handle,
ACE_Reactor_Mask close_mask);
private:
ACE_SSL_SOCK_Acceptor acceptor_;
};
int
Server_Acceptor::open (const ACE_INET_Addr &listen_addr)
{
if (this->acceptor_.open (listen_addr) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("%p\n"),
ACE_TEXT ("listen")),
-1);
return 0;
}
int
Server_Acceptor::handle_input (ACE_HANDLE)
{
ACE_SSL_SOCK_Stream new_stream;
if (this->acceptor_.accept (new_stream) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
ACE_TEXT ("(%t) %p\n"),
ACE_TEXT ("accept")),
-1);
Server_Handler *new_handler = 0;
ACE_NEW_RETURN (new_handler, Server_Handler, -1);
if (new_handler->open (new_stream.get_handle ()) != 0)
delete new_handler;
return 0;
}
int
Server_Acceptor::handle_close (ACE_HANDLE, ACE_Reactor_Mask)
{
this->acceptor_.close ();
return 0;
}
错误:
[root@localhost SSL]# make -f Makefile.test
Makefile.test:75: .depend.Makefile.test: No such file or directory
g++ -fPIC -O -D_REENTRANT -I"../.." -I"/include" -I"/usr/kerberos/include" -DACE_HAS_SSL=1 -D_GNU_SOURCE -DACE_HAS_LINUX_NPTL -DACE_HAS_AIO_CALLS -DACE_HAS_EXCEPTIONS -D__ACE_INLINE__ -c -o "SSL_Test.o" SSL_Test.cpp
SSL_Test.cpp: In destructor virtual Server_Handler::~Server_Handler()?
SSL_Test.cpp:32: error: request for member handle is ambiguous
../../ace/Asynch_IO.h:1843: error: candidates are: virtual void ACE_Handler::handle(ACE_HANDLE)
../../ace/Asynch_IO.h:1840: error: candidates are: virtual ACE_HANDLE ACE_Handler::handle() const
../../ace/Asynch_IO.inl:237: error: ACE_HANDLE ACE_Asynch_Operation::handle() const
SSL_Test.cpp:35: error: request for member handle is ambiguous
../../ace/Asynch_IO.h:1843: error: candidates are: virtual void ACE_Handler::handle(ACE_HANDLE)
../../ace/Asynch_IO.h:1840: error: candidates are: virtual ACE_HANDLE ACE_Handler::handle() const
../../ace/Asynch_IO.inl:237: error: ACE_HANDLE ACE_Asynch_Operation::handle() const
SSL_Test.cpp:42: error: request for member handle is ambiguous
../../ace/Asynch_IO.h:1843: error: candidates are: virtual void ACE_Handler::handle(ACE_HANDLE)
../../ace/Asynch_IO.h:1840: error: candidates are: virtual ACE_HANDLE ACE_Handler::handle() const
../../ace/Asynch_IO.inl:237: error: ACE_HANDLE ACE_Asynch_Operation::handle() const
make: *** [SSL_Test.o] Error 1
project(test):aceexe,ssl{
exename=test
macros+=_GNU_SOURCE ACE_HAS_LINUX_NPTL ACE_HAS_AIO_CALLS ACE_HAS_EXCEPTIONS __ACE_INLINE__
Source_Files {
SSL_Test.cpp
}
}
这是为什么?
[ 本帖最后由 jonathanliu2004 于 2008-12-2 20:05 编辑 ] |
|