Define declarations.
*/
#define DPCHostname "127.0.0.1"
-#define DPCPendingConnections 5
#define DPCPort 6668
#define DPCSessionKeyLength 8
\f
-/*
- Typedef declarations.
-*/
-typedef struct _ClientInfo
-{
- int
- socket;
-} ClientInfo;
-\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
%
*/
-#if defined(MAGICKCORE_HAVE_SOCKET)
static MagickSizeType CRC64(const unsigned char *message,const size_t length)
{
MagickSizeType
crc=crc_xor[(crc ^ message[i]) & 0xff] ^ (crc >> 8);
return(crc);
}
-#endif
static int ConnectPixelCacheServer(const char *hostname,const int port,
MagickSizeType *session_key,ExceptionInfo *exception)
(void) CopyMagickString((char *) session,shared_secret,MaxTextExtent-
DPCSessionKeyLength);
host=gethostbyname(hostname);
- client_socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
+ client_socket=socket(AF_INET,SOCK_STREAM,0);
if (client_socket == -1)
{
(void) ThrowMagickException(exception,GetMagickModule(),CacheError,
%
*/
-#if defined(MAGICKCORE_HAVE_SOCKET)
static MagickBooleanType DestroyDistributeCache(SplayTreeInfo *image_registry,
int file,const MagickSizeType session_key)
{
}
static MagickBooleanType OpenDistributeCache(SplayTreeInfo *image_registry,
- int file,const MagickSizeType session_key)
+ int file,const MagickSizeType session_key,ExceptionInfo *exception)
{
- ExceptionInfo
- *exception;
-
Image
*image;
unsigned char
buffer[MaxTextExtent];
- exception=AcquireExceptionInfo();
image=AcquireImage((ImageInfo *) NULL,exception);
- exception=DestroyExceptionInfo(exception);
if (image == (Image *) NULL)
return(MagickFalse);
length=sizeof(image->columns)+sizeof(image->rows)+
}
static MagickBooleanType ReadDistributeCacheMetacontent(
- SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
+ SplayTreeInfo *image_registry,int file,const MagickSizeType session_key,
+ ExceptionInfo *exception)
{
const unsigned char
*metacontent;
- ExceptionInfo
- *exception;
-
Image
*image;
q+=sizeof(region.width);
(void) memcpy(&length,q,sizeof(length));
q+=sizeof(length);
- exception=AcquireExceptionInfo();
p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
exception);
- exception=DestroyExceptionInfo(exception);
if (p == (const Quantum *) NULL)
return(MagickFalse);
metacontent=GetVirtualMetacontent(image);
}
static MagickBooleanType ReadDistributeCachePixels(
- SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
+ SplayTreeInfo *image_registry,int file,const MagickSizeType session_key,
+ ExceptionInfo *exception)
{
- ExceptionInfo
- *exception;
-
Image
*image;
q+=sizeof(region.width);
(void) memcpy(&length,q,sizeof(length));
q+=sizeof(length);
- exception=AcquireExceptionInfo();
p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
exception);
- exception=DestroyExceptionInfo(exception);
if (p == (const Quantum *) NULL)
return(MagickFalse);
count=send(file,p,length,0);
}
static MagickBooleanType WriteDistributeCacheMetacontent(
- SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
+ SplayTreeInfo *image_registry,int file,const MagickSizeType session_key,
+ ExceptionInfo *exception)
{
- ExceptionInfo
- *exception;
-
Image
*image;
p+=sizeof(region.width);
(void) memcpy(&length,p,sizeof(length));
p+=sizeof(length);
- exception=AcquireExceptionInfo();
q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
exception);
- exception=DestroyExceptionInfo(exception);
if (q == (Quantum *) NULL)
return(MagickFalse);
metacontent=GetAuthenticMetacontent(image);
}
static MagickBooleanType WriteDistributeCachePixels(
- SplayTreeInfo *image_registry,int file,const MagickSizeType session_key)
+ SplayTreeInfo *image_registry,int file,const MagickSizeType session_key,
+ ExceptionInfo *exception)
{
- ExceptionInfo
- *exception;
-
Image
*image;
p+=sizeof(region.width);
(void) memcpy(&length,p,sizeof(length));
p+=sizeof(length);
- exception=AcquireExceptionInfo();
q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
exception);
- exception=DestroyExceptionInfo(exception);
if (q == (Quantum *) NULL)
return(MagickFalse);
count=recv(file,q,length,0);
return(status);
}
-static void *DistributePixelCacheClient(void *client_info)
+static void *DistributePixelCacheClient(void *socket)
{
-#if defined(MAGICKCORE_THREAD_SUPPORT)
const char
*shared_secret;
+ ExceptionInfo
+ *exception;
+
int
client_socket;
command,
session[MaxTextExtent];
- /*
- Deallocate thread resources on return.
- */
- pthread_detach(pthread_self());
- client_socket=((ClientInfo *) client_info)->socket;
- client_info=RelinquishMagickMemory(client_info);
/*
Generate session key.
*/
DPCSessionKeyLength);
session_key=CRC64(session,strlen(shared_secret)+DPCSessionKeyLength);
random_info=DestroyRandomInfo(random_info);
+ exception=AcquireExceptionInfo();
image_registry=NewSplayTree((int (*)(const void *,const void *)) NULL,
(void *(*)(void *)) NULL,(void *(*)(void *)) NULL);
+ client_socket=(*(int *) socket);
count=send(client_socket,GetStringInfoDatum(secret),DPCSessionKeyLength,0);
secret=DestroyStringInfo(secret);
for ( ; ; )
{
case 'o':
{
- status=OpenDistributeCache(image_registry,client_socket,session_key);
+ status=OpenDistributeCache(image_registry,client_socket,session_key,
+ exception);
break;
}
case 'r':
{
status=ReadDistributeCachePixels(image_registry,client_socket,
- session_key);
+ session_key,exception);
break;
}
case 'R':
{
status=ReadDistributeCacheMetacontent(image_registry,client_socket,
- session_key);
+ session_key,exception);
break;
}
case 'w':
{
status=WriteDistributeCachePixels(image_registry,client_socket,
- session_key);
+ session_key,exception);
break;
}
case 'W':
{
status=WriteDistributeCacheMetacontent(image_registry,client_socket,
- session_key);
+ session_key,exception);
break;
}
case 'd':
break;
}
(void) close(client_socket);
+ exception=DestroyExceptionInfo(exception);
image_registry=DestroySplayTree(image_registry);
return((void *) NULL);
-#else
- ThrowFatalException(MissingDelegateError,"POSIX threads");
-#endif
}
-#endif
MagickExport void DistributePixelCacheServer(const size_t port,
ExceptionInfo *exception)
attributes;
pthread_t
- id;
+ threads;
struct sockaddr_in
address;
/*
Launch distributed pixel cache server.
*/
- server_socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
+ server_socket=socket(AF_INET,SOCK_STREAM,0);
address.sin_family=AF_INET;
address.sin_port=htons(port);
address.sin_addr.s_addr=htonl(INADDR_ANY);
sizeof(address));
if (status != 0)
ThrowFatalException(CacheFatalError,"UnableToBind");
- status=listen(server_socket,DPCPendingConnections);
+ status=listen(server_socket,5);
if (status != 0)
ThrowFatalException(CacheFatalError,"UnableToListen");
pthread_attr_init(&attributes);
for ( ; ; )
{
- ClientInfo
- *client_info;
-
int
client_socket;
client_socket=accept(server_socket,(struct sockaddr *) &address,&length);
if (client_socket == -1)
ThrowFatalException(CacheFatalError,"UnableToEstablishConnection");
- client_info=(ClientInfo *) AcquireMagickMemory(sizeof(*client_info));
- if (client_info == (ClientInfo *) NULL)
- ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
- client_info->socket=client_socket;
- status=pthread_create(&id,&attributes,DistributePixelCacheClient,(void *)
- client_info);
+ status=pthread_create(&threads,&attributes,DistributePixelCacheClient,
+ (void *) &client_socket);
if (status == -1)
ThrowFatalException(CacheFatalError,"UnableToCreateClientThread");
}
MagickPrivate MagickBooleanType OpenDistributePixelCache(
DistributeCacheInfo *distribute_cache_info,Image *image)
{
-#if defined(MAGICKCORE_HAVE_SOCKET)
MagickBooleanType
status;
if (count != (ssize_t) sizeof(status))
return(MagickFalse);
return(MagickTrue);
-#else
- return(MagickFalse);
-#endif
}
\f
/*
DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
const MagickSizeType length,unsigned char *metacontent)
{
-#if defined(MAGICKCORE_HAVE_SOCKET)
MagickBooleanType
status;
if (count != (ssize_t) sizeof(status))
return(MagickFalse);
return(status != 0 ? MagickTrue : MagickFalse);
-#else
- return(MagickFalse);
-#endif
}
\f
/*
DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
const MagickSizeType length,unsigned char *pixels)
{
-#if defined(MAGICKCORE_HAVE_SOCKET)
MagickBooleanType
status;
if (count != (ssize_t) sizeof(status))
return(MagickFalse);
return(status != 0 ? MagickTrue : MagickFalse);
-#else
- return(MagickFalse);
-#endif
}
\f
/*
MagickPrivate MagickBooleanType RelinquishDistributePixelCache(
DistributeCacheInfo *distribute_cache_info)
{
-#if defined(MAGICKCORE_HAVE_SOCKET)
register unsigned char
*p;
if (count != (ssize_t) (p-buffer))
return(MagickFalse);
return(MagickTrue);
-#else
- return(MagickFalse);
-#endif
}
\f
/*
DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
const MagickSizeType length,const unsigned char *metacontent)
{
-#if defined(MAGICKCORE_HAVE_SOCKET)
MagickBooleanType
status;
if (count != (ssize_t) sizeof(status))
return(MagickFalse);
return(status != 0 ? MagickTrue : MagickFalse);
-#else
- return(MagickFalse);
-#endif
}
\f
/*
DistributeCacheInfo *distribute_cache_info,const RectangleInfo *region,
const MagickSizeType length,const unsigned char *pixels)
{
-#if defined(MAGICKCORE_HAVE_SOCKET)
MagickBooleanType
status;
if (count != (ssize_t) sizeof(status))
return(MagickFalse);
return(status != 0 ? MagickTrue : MagickFalse);
-#else
- return(MagickFalse);
-#endif
}