DaemonSocket.cpp
资源名称:warftpd.zip [点击查看]
上传用户:surprise9
上传日期:2007-01-04
资源大小:426k
文件大小:3k
源码类别:
Ftp客户端
开发平台:
Visual C++
- // This is part of the WAR SOFTWARE SERIES initiated by Jarle Aase
- // Copyright 1996 by Jarle Aase. All rights reserved.
- // See the "War Software Series Licende Agreement" for details concerning
- // use and distribution.
- // ---
- // This source code, executables and programs containing source code or
- // binaries or proprietetary technology from the War Software Series are
- // NOT alloed used, viewed or tested by any governmental agencies in
- // any countries. This includes the government, departments, police,
- // military etc.
- // ---
- // This file is intended for use with Tab space = 2
- // Created and maintained in MSVC Developer Studio
- // ---
- // NAME : DaemonSocket.cpp
- // PURPOSE : Sockets special to WAR daemons
- // PROGRAM :
- // DATE : Nov. 14 1996
- // AUTHOR : Jarle Aase
- // ---
- // REVISION HISTORY
- //
- #include "stdafx.h"
- #include "WarDaemon.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- ///////////////////////////////////////////////////////////////////////////////////////
- // CDaemonServiceSocket
- CDaemonServiceSocket::CDaemonServiceSocket()
- {
- }
- CDaemonServiceSocket::~CDaemonServiceSocket()
- {
- LogMsg(LOGF_DEBUG,"~CDaemonServiceSocket() - Killing all children.");
- KillAllChildren();
- };
- BOOL CDaemonServiceSocket::DoAccept(CSock *NewSocket )
- {
- if (CSock::DoAccept(NewSocket))
- {
- // Link the socket
- NewSocket->m_Father = this;
- return TRUE;
- }
- return FALSE;
- }
- BOOL CDaemonServiceSocket::Initialize(int PortNumber, LPCSTR ServiceName, LPCSTR ListenIP)
- {
- char buf[127];
- int err;
- SOCKADDR sa;
- SOCKADDR_IN *s_in = (SOCKADDR_IN *)&sa;
- int Len = sizeof(SOCKADDR);
- memset(&sa,0,Len);
- m_SocketName = ServiceName;
- m_PortNumber = PortNumber;
- if (!Create(PortNumber,SOCK_STREAM,FD_ACCEPT,ListenIP))
- {
- err = GetLastError();
- if (err == WSAEADDRINUSE)
- LogMsg(LOGF_ERROR,"Some other service is already using the specified port.");
- else
- {
- sprintf(buf,"CDaemonServiceSocket::Initialize(): Create(%d) failed.", PortNumber);
- LogLastError(LOGF_ERROR,err,buf);
- }
- delete this;
- return FALSE;
- }
- if (!AsyncSelect(FD_ACCEPT))
- {
- LogLastError(LOGF_ERROR,0,"CDaemonServiceSocket::Initialize(): AsyncSelect(FD_ACCEPT) failed");
- delete this;
- return FALSE;
- }
- if (!Listen())
- {
- LogLastError(LOGF_ERROR,0,"CDaemonServiceSocket::Initialize(): Listen() failed.");
- delete this;
- return FALSE;
- }
- GetSockName(&sa, &Len);
- if (m_Log)
- {
- m_Log->LogMsg(LOGF_SYSTEM,"%s daemon online on %d.%d.%d.%d port %u",
- SafeStringIndex(DaemonTypes,m_Type, LT_INVALID),
- s_in->sin_addr.S_un.S_un_b.s_b1,
- s_in->sin_addr.S_un.S_un_b.s_b2,
- s_in->sin_addr.S_un.S_un_b.s_b3,
- s_in->sin_addr.S_un.S_un_b.s_b4,
- ntohs(s_in->sin_port));
- }
- return TRUE;
- }