2006-01-19 00:34:21 +01:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
2006-01-31 23:01:47 +01:00
|
|
|
* Copyright (C) 2005-2006 Novell, Inc. Inc. All Rights Reserved.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2006-01-31 23:01:47 +01:00
|
|
|
* Library Lesser General Public License for more details.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-01-31 23:01:47 +01:00
|
|
|
* License along with this library; if not, Novell, Inc.
|
2006-01-19 00:34:21 +01:00
|
|
|
*
|
|
|
|
* To contact Novell about this file by physical or electronic mail,
|
|
|
|
* you may find current contact information at www.novell.com.
|
|
|
|
*
|
|
|
|
***********************************************************************/
|
|
|
|
|
2006-01-31 23:01:47 +01:00
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
using System;
|
|
|
|
using System.Net;
|
|
|
|
using System.Net.Sockets;
|
2006-01-10 00:44:00 +01:00
|
|
|
using Mono.Unix.Native;
|
2005-10-11 21:51:00 +02:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading;
|
|
|
|
using sscs.common;
|
|
|
|
using sscs.constants;
|
|
|
|
|
|
|
|
namespace sscs.communication
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Platform specific class which implements
|
|
|
|
* the 'Communication' interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class UnixCommunication : Communication
|
|
|
|
{
|
|
|
|
private Socket listeningSocket;
|
|
|
|
private Socket connectedSocket;
|
|
|
|
private string socketFileName = "/tmp/.novellCASA";
|
2006-01-10 00:44:00 +01:00
|
|
|
private Mono.Unix.UnixEndPoint sockEndPoint;
|
2005-10-11 21:51:00 +02:00
|
|
|
private ManualResetEvent eventVar = null;
|
|
|
|
|
|
|
|
|
|
|
|
//Methods
|
|
|
|
internal UnixCommunication()
|
|
|
|
{
|
|
|
|
CSSSLogger.ExecutionTrace(this);
|
|
|
|
Syscall.umask(0);
|
|
|
|
if(File.Exists(socketFileName))
|
|
|
|
File.Delete(socketFileName);
|
|
|
|
listeningSocket = new Socket( AddressFamily.Unix,
|
|
|
|
SocketType.Stream,
|
|
|
|
ProtocolType.IP );
|
2006-01-10 00:44:00 +01:00
|
|
|
sockEndPoint = new Mono.Unix.UnixEndPoint(socketFileName);
|
2005-10-11 21:51:00 +02:00
|
|
|
eventVar = new ManualResetEvent(true);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~UnixCommunication()
|
|
|
|
{
|
|
|
|
CSSSLogger.ExecutionTrace(this);
|
|
|
|
eventVar.Close();
|
|
|
|
CloseCommunicationEndPoint();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// This code executes in the listening thread.
|
|
|
|
public void StartCommunicationEndPoint()
|
|
|
|
{
|
|
|
|
CSSSLogger.ExecutionTrace(this);
|
|
|
|
try
|
|
|
|
{
|
|
|
|
listeningSocket.Bind(sockEndPoint);
|
|
|
|
listeningSocket.Listen(50);
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
CSSSLogger.ExpLog(e.ToString());
|
|
|
|
}
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eventVar.Reset();
|
|
|
|
listeningSocket.BeginAccept(new AsyncCallback(ListenCb),
|
|
|
|
listeningSocket);
|
|
|
|
eventVar.WaitOne();
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
CSSSLogger.ExpLog(e.ToString());
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CloseCommunicationEndPoint()
|
|
|
|
{
|
|
|
|
CSSSLogger.ExecutionTrace(this);
|
|
|
|
listeningSocket.Close();
|
|
|
|
if(File.Exists( socketFileName ))
|
|
|
|
File.Delete(socketFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// On receipt of a new client, this method is called.
|
|
|
|
private void ListenCb (IAsyncResult state)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
CSSSLogger.ExecutionTrace(this);
|
|
|
|
connectedSocket = ((Socket)state.AsyncState).EndAccept (state);
|
|
|
|
eventVar.Set();
|
|
|
|
ServiceClient();
|
|
|
|
}
|
|
|
|
catch(Exception e)
|
|
|
|
{
|
|
|
|
/* All resources would have been cleaned up before reaching
|
|
|
|
* here.
|
|
|
|
*/
|
|
|
|
CSSSLogger.ExpLog(e.ToString());
|
|
|
|
}
|
|
|
|
/* End of thread function */
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ServiceClient()
|
|
|
|
{
|
|
|
|
CSSSLogger.ExecutionTrace(this);
|
|
|
|
IPCChannel ipcChannel = IPCChannel.Create(connectedSocket);
|
|
|
|
AppHandler appHandler = new AppHandler(ipcChannel);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int retVal = appHandler.ServiceApp();
|
|
|
|
if( retVal != RetCodes.SUCCESS )
|
|
|
|
CSSSLogger.DbgLog("Servicing client failed.");
|
|
|
|
}
|
|
|
|
catch( Exception e )
|
|
|
|
{
|
|
|
|
CSSSLogger.ExpLog(e.ToString());
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
ipcChannel.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|