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,0);
+ client_socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
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)
{
return(status);
}
-static void *DistributePixelCacheClient(void *socket)
+static void *DistributePixelCacheClient(void *client_info)
{
+#if defined(MAGICKCORE_THREAD_SUPPORT)
const char
*shared_secret;
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.
*/
random_info=DestroyRandomInfo(random_info);
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 ( ; ; )
(void) close(client_socket);
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
- threads;
+ id;
struct sockaddr_in
address;
/*
Launch distributed pixel cache server.
*/
- server_socket=socket(AF_INET,SOCK_STREAM,0);
+ server_socket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
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,5);
+ status=listen(server_socket,DPCPendingConnections);
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");
- status=pthread_create(&threads,&attributes,DistributePixelCacheClient,
- (void *) &client_socket);
+ 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);
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
}