54#include "MagickCore/studio.h"
55#include "MagickCore/cache.h"
56#include "MagickCore/cache-private.h"
57#include "MagickCore/distribute-cache.h"
58#include "MagickCore/distribute-cache-private.h"
59#include "MagickCore/exception.h"
60#include "MagickCore/exception-private.h"
61#include "MagickCore/geometry.h"
62#include "MagickCore/image.h"
63#include "MagickCore/image-private.h"
64#include "MagickCore/list.h"
65#include "MagickCore/locale_.h"
66#include "MagickCore/memory_.h"
67#include "MagickCore/nt-base-private.h"
68#include "MagickCore/pixel.h"
69#include "MagickCore/policy.h"
70#include "MagickCore/random_.h"
71#include "MagickCore/registry.h"
72#include "MagickCore/splay-tree.h"
73#include "MagickCore/string_.h"
74#include "MagickCore/string-private.h"
75#include "MagickCore/version.h"
76#include "MagickCore/version-private.h"
77#undef MAGICKCORE_HAVE_DISTRIBUTE_CACHE
78#if defined(MAGICKCORE_DPC_SUPPORT)
79#if defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_THREAD_SUPPORT)
80#include <netinet/in.h>
82#include <sys/socket.h>
84#define CLOSE_SOCKET(socket) (void) close(socket)
85#define HANDLER_RETURN_TYPE void *
86#define HANDLER_RETURN_VALUE (void *) NULL
87#define SOCKET_TYPE int
88#define LENGTH_TYPE size_t
89#define MAGICKCORE_HAVE_DISTRIBUTE_CACHE 1
90#elif defined(_MSC_VER)
91#define CLOSE_SOCKET(socket) (void) closesocket(socket)
92#define HANDLER_RETURN_TYPE DWORD WINAPI
93#define HANDLER_RETURN_VALUE 0
94#define SOCKET_TYPE SOCKET
95#define LENGTH_TYPE int
96#define MAGICKCORE_HAVE_DISTRIBUTE_CACHE 1
97#define MAGICKCORE_HAVE_WINSOCK2 1
104#define DPCHostname "127.0.0.1"
105#define DPCPendingConnections 10
107#define DPCSessionKeyLength 8
109# define MSG_NOSIGNAL 0
115#ifdef MAGICKCORE_HAVE_WINSOCK2
120 *wsaData = (WSADATA*) NULL;
146#if !defined(MAGICKCORE_HAVE_DISTRIBUTE_CACHE)
147static inline MagickOffsetType dpc_read(
int magick_unused(file),
148 const MagickSizeType magick_unused(length),
149 unsigned char *magick_restrict magick_unused(message))
151 magick_unreferenced(file);
152 magick_unreferenced(length);
153 magick_unreferenced(message);
157static inline MagickOffsetType dpc_read(
int file,
const MagickSizeType length,
158 unsigned char *magick_restrict message)
167 for (i=0; i < (MagickOffsetType) length; i+=count)
169 count=recv(file,(
char *) message+i,(LENGTH_TYPE) MagickMin(length-
170 (MagickSizeType) i,(MagickSizeType) MagickMaxBufferExtent),0);
182#if defined(MAGICKCORE_HAVE_WINSOCK2)
183static void InitializeWinsock2(MagickBooleanType use_lock)
185 if (use_lock != MagickFalse)
188 ActivateSemaphoreInfo(&winsock2_semaphore);
189 LockSemaphoreInfo(winsock2_semaphore);
191 if (wsaData == (WSADATA *) NULL)
193 wsaData=(WSADATA *) AcquireMagickMemory(
sizeof(WSADATA));
194 if (WSAStartup(MAKEWORD(2,2),wsaData) != 0)
195 ThrowFatalException(CacheFatalError,
"WSAStartup failed");
197 if (use_lock != MagickFalse)
198 UnlockSemaphoreInfo(winsock2_semaphore);
202#if !defined(MAGICKCORE_HAVE_DISTRIBUTE_CACHE)
203static int ConnectPixelCacheServer(
const char *magick_unused(hostname),
204 const int magick_unused(port),
size_t *magick_unused(session_key),
207 magick_unreferenced(hostname);
208 magick_unreferenced(port);
209 magick_unreferenced(session_key);
210 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
211 "DelegateLibrarySupportNotBuiltIn",
"distributed pixel cache");
215static int ConnectPixelCacheServer(
const char *hostname,
const int port,
219 service[MagickPathExtent],
242#if defined(MAGICKCORE_HAVE_WINSOCK2)
243 InitializeWinsock2(MagickTrue);
245 (void) memset(&hint,0,
sizeof(hint));
246 hint.ai_family=AF_INET;
247 hint.ai_socktype=SOCK_STREAM;
248 hint.ai_flags=AI_PASSIVE;
249 (void) FormatLocaleString(service,MagickPathExtent,
"%d",port);
250 status=getaddrinfo(hostname,service,&hint,&result);
253 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
254 "DistributedPixelCache",
"'%s': %s",hostname,GetExceptionMessage(errno));
257 client_socket=socket(result->ai_family,result->ai_socktype,
258 result->ai_protocol);
259 if (client_socket == -1)
261 freeaddrinfo(result);
262 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
263 "DistributedPixelCache",
"'%s': %s",hostname,GetExceptionMessage(errno));
266 status=connect(client_socket,result->ai_addr,(socklen_t) result->ai_addrlen);
267 freeaddrinfo(result);
270 CLOSE_SOCKET(client_socket);
271 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
272 "DistributedPixelCache",
"'%s': %s",hostname,GetExceptionMessage(errno));
275 count=recv(client_socket,(
char *) session_key,
sizeof(*session_key),0);
278 CLOSE_SOCKET(client_socket);
279 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
280 "DistributedPixelCache",
"'%s': %s",hostname,GetExceptionMessage(errno));
286 shared_secret=GetPolicyValue(
"cache:shared-secret");
287 if (shared_secret == (
char *) NULL)
289 CLOSE_SOCKET(client_socket);
290 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
291 "DistributedPixelCache",
"'%s': shared secret required",hostname);
294 nonce=StringToStringInfo(shared_secret);
295 if (GetMagickSignature(nonce) != *session_key)
297 CLOSE_SOCKET(client_socket);
298 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
299 "DistributedPixelCache",
"'%s' authentication failed",hostname);
302 shared_secret=DestroyString(shared_secret);
303 nonce=DestroyStringInfo(nonce);
304 return(client_socket);
327 hosts=(
char *) GetImageRegistry(StringRegistryType,
"cache:hosts",exception);
328 if (hosts == (
char *) NULL)
331 return(AcquireString(DPCHostname));
333 (void) SubstituteString(&hosts,
",",
" ");
334 hostlist=StringToArgv(hosts,&argc);
335 hosts=DestroyString(hosts);
336 if (hostlist == (
char **) NULL)
339 return(AcquireString(DPCHostname));
341 hosts=AcquireString(hostlist[(
id++ % ((
size_t) argc-1))+1]);
342 for (i=0; i < (ssize_t) argc; i++)
343 hostlist[i]=DestroyString(hostlist[i]);
344 hostlist=(
char **) RelinquishMagickMemory(hostlist);
345 (void) SubstituteString(&hosts,
":",
" ");
346 hostlist=StringToArgv(hosts,&argc);
347 if (hostlist == (
char **) NULL)
350 return(AcquireString(DPCHostname));
352 host=AcquireString(hostlist[1]);
353 if (hostlist[2] == (
char *) NULL)
356 *port=StringToLong(hostlist[2]);
357 for (i=0; i < (ssize_t) argc; i++)
358 hostlist[i]=DestroyString(hostlist[i]);
359 hostlist=(
char **) RelinquishMagickMemory(hostlist);
379 sizeof(*server_info));
380 (void) memset(server_info,0,
sizeof(*server_info));
381 server_info->signature=MagickCoreSignature;
383 hostname=GetHostname(&server_info->port,exception);
385 server_info->file=ConnectPixelCacheServer(hostname,server_info->port,
386 &session_key,exception);
387 if (server_info->file == -1)
388 server_info=DestroyDistributeCacheInfo(server_info);
391 server_info->session_key=session_key;
392 (void) CopyMagickString(server_info->hostname,hostname,MagickPathExtent);
393 server_info->debug=(GetLogEventMask() & CacheEvent) != 0 ? MagickTrue :
396 hostname=DestroyString(hostname);
428 assert(server_info->signature == MagickCoreSignature);
429#if defined(MAGICKCORE_HAVE_DISTRIBUTE_CACHE)
430 if (server_info->file > 0)
431 CLOSE_SOCKET(server_info->file);
433 server_info->signature=(~MagickCoreSignature);
464#if !defined(MAGICKCORE_HAVE_DISTRIBUTE_CACHE)
465static inline MagickOffsetType dpc_send(
int magick_unused(file),
466 const MagickSizeType magick_unused(length),
467 const void *magick_restrict magick_unused(message))
469 magick_unreferenced(file);
470 magick_unreferenced(length);
471 magick_unreferenced(message);
475static inline MagickOffsetType dpc_send(
int file,
const MagickSizeType length,
476 const void *magick_restrict message)
488 for (i=0; i < (MagickOffsetType) length; i+=count)
490 count=(MagickOffsetType) send(file,(
char *) message+i,(LENGTH_TYPE)
491 MagickMin(length-(MagickSizeType) i,(MagickSizeType) MagickMaxBufferExtent),
504#if !defined(MAGICKCORE_HAVE_DISTRIBUTE_CACHE)
505MagickExport
void DistributePixelCacheServer(
const int magick_unused(port),
508 magick_unreferenced(port);
509 magick_unreferenced(exception);
510 ThrowFatalException(MissingDelegateError,
"DelegateLibrarySupportNotBuiltIn");
513static MagickBooleanType DestroyDistributeCache(
SplayTreeInfo *registry,
514 const size_t session_key)
517 key = (MagickAddressType) session_key;
522 return(DeleteNodeFromSplayTree(registry,(
const void *) key));
525static MagickBooleanType OpenDistributeCache(
SplayTreeInfo *registry,
int file,
532 key = (MagickAddressType) session_key;
544 message[MagickPathExtent],
550 image=AcquireImage((
ImageInfo *) NULL,exception);
551 if (image == (
Image *) NULL)
553 length=
sizeof(image->storage_class)+
sizeof(image->colorspace)+
554 sizeof(image->alpha_trait)+
sizeof(image->channels)+
sizeof(image->columns)+
555 sizeof(image->rows)+
sizeof(image->number_channels)+MaxPixelChannels*
556 sizeof(*image->channel_map)+
sizeof(image->metacontent_extent);
557 count=dpc_read(file,length,message);
558 if (count != (MagickOffsetType) length)
564 (void) memcpy(&image->storage_class,p,
sizeof(image->storage_class));
565 p+=(ptrdiff_t)
sizeof(image->storage_class);
566 (void) memcpy(&image->colorspace,p,
sizeof(image->colorspace));
567 p+=(ptrdiff_t)
sizeof(image->colorspace);
568 (void) memcpy(&image->alpha_trait,p,
sizeof(image->alpha_trait));
569 p+=(ptrdiff_t)
sizeof(image->alpha_trait);
570 (void) memcpy(&image->channels,p,
sizeof(image->channels));
571 p+=(ptrdiff_t)
sizeof(image->channels);
572 (void) memcpy(&image->columns,p,
sizeof(image->columns));
573 p+=(ptrdiff_t)
sizeof(image->columns);
574 (void) memcpy(&image->rows,p,
sizeof(image->rows));
575 p+=(ptrdiff_t)
sizeof(image->rows);
576 (void) memcpy(&image->number_channels,p,
sizeof(image->number_channels));
577 p+=(ptrdiff_t)
sizeof(image->number_channels);
578 (void) memcpy(image->channel_map,p,MaxPixelChannels*
579 sizeof(*image->channel_map));
580 p+=(ptrdiff_t) MaxPixelChannels*
sizeof(*image->channel_map);
581 (void) memcpy(&image->metacontent_extent,p,
sizeof(image->metacontent_extent));
582 p+=(ptrdiff_t)
sizeof(image->metacontent_extent);
583 if (SyncImagePixelCache(image,exception) == MagickFalse)
585 status=AddValueToSplayTree(registry,(
const void *) key,image);
589static MagickBooleanType ReadDistributeCacheMetacontent(
SplayTreeInfo *registry,
602 key = (MagickAddressType) session_key;
614 message[MagickPathExtent],
620 image=(
Image *) GetValueFromSplayTree(registry,(
const void *) key);
621 if (image == (
Image *) NULL)
623 length=
sizeof(region.width)+
sizeof(region.height)+
sizeof(region.x)+
624 sizeof(region.y)+
sizeof(length);
625 count=dpc_read(file,length,message);
626 if (count != (MagickOffsetType) length)
629 (void) memcpy(®ion.width,q,
sizeof(region.width));
630 q+=(ptrdiff_t)
sizeof(region.width);
631 (void) memcpy(®ion.height,q,
sizeof(region.height));
632 q+=(ptrdiff_t)
sizeof(region.height);
633 (void) memcpy(®ion.x,q,
sizeof(region.x));
634 q+=(ptrdiff_t)
sizeof(region.x);
635 (void) memcpy(®ion.y,q,
sizeof(region.y));
636 q+=(ptrdiff_t)
sizeof(region.y);
637 (void) memcpy(&length,q,
sizeof(length));
638 q+=(ptrdiff_t)
sizeof(length);
639 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
641 if (p == (
const Quantum *) NULL)
643 metacontent=(
const unsigned char *) GetVirtualMetacontent(image);
644 count=dpc_send(file,length,metacontent);
645 if (count != (MagickOffsetType) length)
650static MagickBooleanType ReadDistributeCachePixels(
SplayTreeInfo *registry,
660 key = (MagickAddressType) session_key;
672 message[MagickPathExtent],
678 image=(
Image *) GetValueFromSplayTree(registry,(
const void *) key);
679 if (image == (
Image *) NULL)
681 length=
sizeof(region.width)+
sizeof(region.height)+
sizeof(region.x)+
682 sizeof(region.y)+
sizeof(length);
683 count=dpc_read(file,length,message);
684 if (count != (MagickOffsetType) length)
687 (void) memcpy(®ion.width,q,
sizeof(region.width));
688 q+=(ptrdiff_t)
sizeof(region.width);
689 (void) memcpy(®ion.height,q,
sizeof(region.height));
690 q+=(ptrdiff_t)
sizeof(region.height);
691 (void) memcpy(®ion.x,q,
sizeof(region.x));
692 q+=(ptrdiff_t)
sizeof(region.x);
693 (void) memcpy(®ion.y,q,
sizeof(region.y));
694 q+=(ptrdiff_t)
sizeof(region.y);
695 (void) memcpy(&length,q,
sizeof(length));
696 q+=(ptrdiff_t)
sizeof(length);
697 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
699 if (p == (
const Quantum *) NULL)
701 count=dpc_send(file,length,p);
702 if (count != (MagickOffsetType) length)
707static void *RelinquishImageRegistry(
void *image)
709 return((
void *) DestroyImageList((
Image *) image));
712static MagickBooleanType WriteDistributeCacheMetacontent(
720 key = (MagickAddressType) session_key;
735 message[MagickPathExtent],
743 image=(
Image *) GetValueFromSplayTree(registry,(
const void *) key);
744 if (image == (
Image *) NULL)
746 length=
sizeof(region.width)+
sizeof(region.height)+
sizeof(region.x)+
747 sizeof(region.y)+
sizeof(length);
748 count=dpc_read(file,length,message);
749 if (count != (MagickOffsetType) length)
752 (void) memcpy(®ion.width,p,
sizeof(region.width));
753 p+=(ptrdiff_t)
sizeof(region.width);
754 (void) memcpy(®ion.height,p,
sizeof(region.height));
755 p+=(ptrdiff_t)
sizeof(region.height);
756 (void) memcpy(®ion.x,p,
sizeof(region.x));
757 p+=(ptrdiff_t)
sizeof(region.x);
758 (void) memcpy(®ion.y,p,
sizeof(region.y));
759 p+=(ptrdiff_t)
sizeof(region.y);
760 (void) memcpy(&length,p,
sizeof(length));
761 p+=(ptrdiff_t)
sizeof(length);
762 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
764 if (q == (Quantum *) NULL)
766 metacontent=(
unsigned char *) GetAuthenticMetacontent(image);
767 count=dpc_read(file,length,metacontent);
768 if (count != (MagickOffsetType) length)
770 return(SyncAuthenticPixels(image,exception));
773static MagickBooleanType WriteDistributeCachePixels(
SplayTreeInfo *registry,
780 key = (MagickAddressType) session_key;
795 message[MagickPathExtent],
801 image=(
Image *) GetValueFromSplayTree(registry,(
const void *) key);
802 if (image == (
Image *) NULL)
804 length=
sizeof(region.width)+
sizeof(region.height)+
sizeof(region.x)+
805 sizeof(region.y)+
sizeof(length);
806 count=dpc_read(file,length,message);
807 if (count != (MagickOffsetType) length)
810 (void) memcpy(®ion.width,p,
sizeof(region.width));
811 p+=(ptrdiff_t)
sizeof(region.width);
812 (void) memcpy(®ion.height,p,
sizeof(region.height));
813 p+=(ptrdiff_t)
sizeof(region.height);
814 (void) memcpy(®ion.x,p,
sizeof(region.x));
815 p+=(ptrdiff_t)
sizeof(region.x);
816 (void) memcpy(®ion.y,p,
sizeof(region.y));
817 p+=(ptrdiff_t)
sizeof(region.y);
818 (void) memcpy(&length,p,
sizeof(length));
819 p+=(ptrdiff_t)
sizeof(length);
820 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
822 if (q == (Quantum *) NULL)
824 count=dpc_read(file,length,(
unsigned char *) q);
825 if (count != (MagickOffsetType) length)
827 return(SyncAuthenticPixels(image,exception));
830static HANDLER_RETURN_TYPE DistributePixelCacheClient(
void *socket)
839 status = MagickFalse;
863 shared_secret=GetPolicyValue(
"cache:shared-secret");
864 if (shared_secret == (
char *) NULL)
865 ThrowFatalException(CacheFatalError,
"shared secret required");
866 nonce=StringToStringInfo(shared_secret);
867 shared_secret=DestroyString(shared_secret);
868 session_key=GetMagickSignature(nonce);
869 nonce=DestroyStringInfo(nonce);
870 exception=AcquireExceptionInfo();
874 registry=NewSplayTree((
int (*)(
const void *,
const void *)) NULL,
875 (
void *(*)(
void *)) NULL,RelinquishImageRegistry);
876 client_socket=(*(SOCKET_TYPE *) socket);
877 count=dpc_send(client_socket,
sizeof(session_key),&session_key);
878 for (status=MagickFalse; ; )
880 count=dpc_read(client_socket,1,(
unsigned char *) &command);
883 count=dpc_read(client_socket,
sizeof(key),(
unsigned char *) &key);
884 if ((count != (MagickOffsetType)
sizeof(key)) || (key != session_key))
890 status=OpenDistributeCache(registry,client_socket,session_key,
892 count=dpc_send(client_socket,
sizeof(status),&status);
897 status=ReadDistributeCachePixels(registry,client_socket,session_key,
903 status=ReadDistributeCacheMetacontent(registry,client_socket,
904 session_key,exception);
909 status=WriteDistributeCachePixels(registry,client_socket,session_key,
915 status=WriteDistributeCacheMetacontent(registry,client_socket,
916 session_key,exception);
921 status=DestroyDistributeCache(registry,session_key);
927 if (status == MagickFalse)
932 count=dpc_send(client_socket,
sizeof(status),&status);
933 CLOSE_SOCKET(client_socket);
934 exception=DestroyExceptionInfo(exception);
935 registry=DestroySplayTree(registry);
936 return(HANDLER_RETURN_VALUE);
939MagickExport
void DistributePixelCacheServer(
const int port,
943 service[MagickPathExtent];
948#if defined(MAGICKCORE_THREAD_SUPPORT)
954#elif defined(_MSC_VER)
978 assert(exception->signature == MagickCoreSignature);
979 magick_unreferenced(exception);
980#if defined(MAGICKCORE_HAVE_WINSOCK2)
981 InitializeWinsock2(MagickFalse);
983 (void) memset(&hint,0,
sizeof(hint));
984 hint.ai_family=AF_INET;
985 hint.ai_socktype=SOCK_STREAM;
986 hint.ai_flags=AI_PASSIVE;
987 (void) FormatLocaleString(service,MagickPathExtent,
"%d",port);
988 status=getaddrinfo((
const char *) NULL,service,&hint,&result);
990 ThrowFatalException(CacheFatalError,
"UnableToListen");
991 server_socket=(SOCKET_TYPE) 0;
992 for (p=result; p != (
struct addrinfo *) NULL; p=p->ai_next)
997 server_socket=socket(p->ai_family,p->ai_socktype,p->ai_protocol);
998 if (server_socket == -1)
1001 status=setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,(
char *) &one,
1002 (socklen_t)
sizeof(one));
1005 CLOSE_SOCKET(server_socket);
1008 status=bind(server_socket,p->ai_addr,(socklen_t) p->ai_addrlen);
1011 CLOSE_SOCKET(server_socket);
1016 if (p == (
struct addrinfo *) NULL)
1017 ThrowFatalException(CacheFatalError,
"UnableToBind");
1018 freeaddrinfo(result);
1019 status=listen(server_socket,DPCPendingConnections);
1021 ThrowFatalException(CacheFatalError,
"UnableToListen");
1022#if defined(MAGICKCORE_THREAD_SUPPORT)
1023 pthread_attr_init(&attributes);
1033 length=(socklen_t)
sizeof(address);
1034 client_socket=accept(server_socket,(
struct sockaddr *) &address,&length);
1035 if (client_socket == -1)
1036 ThrowFatalException(CacheFatalError,
"UnableToEstablishConnection");
1037#if defined(MAGICKCORE_THREAD_SUPPORT)
1038 status=pthread_create(&threads,&attributes,DistributePixelCacheClient,
1039 (
void *) &client_socket);
1041 ThrowFatalException(CacheFatalError,
"UnableToCreateClientThread");
1042#elif defined(_MSC_VER)
1043 if (CreateThread(0,0,DistributePixelCacheClient,(
void*) &client_socket,0,&threadID) == (HANDLE) NULL)
1044 ThrowFatalException(CacheFatalError,
"UnableToCreateClientThread");
1066MagickPrivate
void DistributeCacheTerminus(
void)
1068#ifdef MAGICKCORE_HAVE_WINSOCK2
1070 ActivateSemaphoreInfo(&winsock2_semaphore);
1071 LockSemaphoreInfo(winsock2_semaphore);
1072 if (wsaData != (WSADATA *) NULL)
1075 wsaData=(WSADATA *) RelinquishMagickMemory((
void *) wsaData);
1077 UnlockSemaphoreInfo(winsock2_semaphore);
1078 RelinquishSemaphoreInfo(&winsock2_semaphore);
1108 assert(server_info->signature == MagickCoreSignature);
1109 return(server_info->file);
1136MagickPrivate
const char *GetDistributeCacheHostname(
1140 assert(server_info->signature == MagickCoreSignature);
1141 return(server_info->hostname);
1170 assert(server_info->signature == MagickCoreSignature);
1171 return(server_info->port);
1199MagickPrivate MagickBooleanType OpenDistributePixelCache(
1209 message[MagickPathExtent],
1216 assert(server_info->signature == MagickCoreSignature);
1217 assert(image != (
Image *) NULL);
1218 assert(image->signature == MagickCoreSignature);
1224 (void) memcpy(p,&server_info->session_key,
sizeof(server_info->session_key));
1225 p+=(ptrdiff_t)
sizeof(server_info->session_key);
1226 (void) memcpy(p,&image->storage_class,
sizeof(image->storage_class));
1227 p+=(ptrdiff_t)
sizeof(image->storage_class);
1228 (void) memcpy(p,&image->colorspace,
sizeof(image->colorspace));
1229 p+=(ptrdiff_t)
sizeof(image->colorspace);
1230 (void) memcpy(p,&image->alpha_trait,
sizeof(image->alpha_trait));
1231 p+=(ptrdiff_t)
sizeof(image->alpha_trait);
1232 (void) memcpy(p,&image->channels,
sizeof(image->channels));
1233 p+=(ptrdiff_t)
sizeof(image->channels);
1234 (void) memcpy(p,&image->columns,
sizeof(image->columns));
1235 p+=(ptrdiff_t)
sizeof(image->columns);
1236 (void) memcpy(p,&image->rows,
sizeof(image->rows));
1237 p+=(ptrdiff_t)
sizeof(image->rows);
1238 (void) memcpy(p,&image->number_channels,
sizeof(image->number_channels));
1239 p+=(ptrdiff_t)
sizeof(image->number_channels);
1240 (void) memcpy(p,image->channel_map,MaxPixelChannels*
1241 sizeof(*image->channel_map));
1242 p+=(ptrdiff_t) MaxPixelChannels*
sizeof(*image->channel_map);
1243 (void) memcpy(p,&image->metacontent_extent,
sizeof(image->metacontent_extent));
1244 p+=(ptrdiff_t)
sizeof(image->metacontent_extent);
1245 count=dpc_send(server_info->file,(MagickSizeType) (p-message),message);
1246 if (count != (MagickOffsetType) (p-message))
1247 return(MagickFalse);
1249 count=dpc_read(server_info->file,
sizeof(status),(
unsigned char *) &status);
1250 if (count != (MagickOffsetType)
sizeof(status))
1251 return(MagickFalse);
1288MagickPrivate MagickOffsetType ReadDistributePixelCacheMetacontent(
1290 const MagickSizeType length,
unsigned char *metacontent)
1296 message[MagickPathExtent],
1303 assert(server_info->signature == MagickCoreSignature);
1305 assert(metacontent != (
unsigned char *) NULL);
1306 if (length > (MagickSizeType) MAGICK_SSIZE_MAX)
1310 (void) memcpy(p,&server_info->session_key,
sizeof(server_info->session_key));
1311 p+=(ptrdiff_t)
sizeof(server_info->session_key);
1312 (void) memcpy(p,®ion->width,
sizeof(region->width));
1313 p+=(ptrdiff_t)
sizeof(region->width);
1314 (void) memcpy(p,®ion->height,
sizeof(region->height));
1315 p+=(ptrdiff_t)
sizeof(region->height);
1316 (void) memcpy(p,®ion->x,
sizeof(region->x));
1317 p+=(ptrdiff_t)
sizeof(region->x);
1318 (void) memcpy(p,®ion->y,
sizeof(region->y));
1319 p+=(ptrdiff_t)
sizeof(region->y);
1320 (void) memcpy(p,&length,
sizeof(length));
1321 p+=(ptrdiff_t)
sizeof(length);
1322 count=dpc_send(server_info->file,(MagickSizeType) (p-message),message);
1323 if (count != (MagickOffsetType) (p-message))
1325 return(dpc_read(server_info->file,length,metacontent));
1361MagickPrivate MagickOffsetType ReadDistributePixelCachePixels(
1363 const MagickSizeType length,
unsigned char *magick_restrict pixels)
1369 message[MagickPathExtent],
1376 assert(server_info->signature == MagickCoreSignature);
1378 assert(pixels != (
unsigned char *) NULL);
1379 if (length > (MagickSizeType) MAGICK_SSIZE_MAX)
1383 (void) memcpy(p,&server_info->session_key,
sizeof(server_info->session_key));
1384 p+=(ptrdiff_t)
sizeof(server_info->session_key);
1385 (void) memcpy(p,®ion->width,
sizeof(region->width));
1386 p+=(ptrdiff_t)
sizeof(region->width);
1387 (void) memcpy(p,®ion->height,
sizeof(region->height));
1388 p+=(ptrdiff_t)
sizeof(region->height);
1389 (void) memcpy(p,®ion->x,
sizeof(region->x));
1390 p+=(ptrdiff_t)
sizeof(region->x);
1391 (void) memcpy(p,®ion->y,
sizeof(region->y));
1392 p+=(ptrdiff_t)
sizeof(region->y);
1393 (void) memcpy(p,&length,
sizeof(length));
1394 p+=(ptrdiff_t)
sizeof(length);
1395 count=dpc_send(server_info->file,(MagickSizeType) (p-message),message);
1396 if (count != (MagickOffsetType) (p-message))
1398 return(dpc_read(server_info->file,length,pixels));
1425MagickPrivate MagickBooleanType RelinquishDistributePixelCache(
1435 message[MagickPathExtent],
1442 assert(server_info->signature == MagickCoreSignature);
1445 (void) memcpy(p,&server_info->session_key,
sizeof(server_info->session_key));
1446 p+=(ptrdiff_t)
sizeof(server_info->session_key);
1447 count=dpc_send(server_info->file,(MagickSizeType) (p-message),message);
1448 if (count != (MagickOffsetType) (p-message))
1449 return(MagickFalse);
1451 count=dpc_read(server_info->file,
sizeof(status),(
unsigned char *) &status);
1452 if (count != (MagickOffsetType)
sizeof(status))
1453 return(MagickFalse);
1490MagickPrivate MagickOffsetType WriteDistributePixelCacheMetacontent(
1492 const MagickSizeType length,
const unsigned char *metacontent)
1498 message[MagickPathExtent],
1505 assert(server_info->signature == MagickCoreSignature);
1507 assert(metacontent != (
unsigned char *) NULL);
1508 if (length > (MagickSizeType) MAGICK_SSIZE_MAX)
1512 (void) memcpy(p,&server_info->session_key,
sizeof(server_info->session_key));
1513 p+=(ptrdiff_t)
sizeof(server_info->session_key);
1514 (void) memcpy(p,®ion->width,
sizeof(region->width));
1515 p+=(ptrdiff_t)
sizeof(region->width);
1516 (void) memcpy(p,®ion->height,
sizeof(region->height));
1517 p+=(ptrdiff_t)
sizeof(region->height);
1518 (void) memcpy(p,®ion->x,
sizeof(region->x));
1519 p+=(ptrdiff_t)
sizeof(region->x);
1520 (void) memcpy(p,®ion->y,
sizeof(region->y));
1521 p+=(ptrdiff_t)
sizeof(region->y);
1522 (void) memcpy(p,&length,
sizeof(length));
1523 p+=(ptrdiff_t)
sizeof(length);
1524 count=dpc_send(server_info->file,(MagickSizeType) (p-message),message);
1525 if (count != (MagickOffsetType) (p-message))
1527 return(dpc_send(server_info->file,length,metacontent));
1564MagickPrivate MagickOffsetType WriteDistributePixelCachePixels(
1566 const MagickSizeType length,
const unsigned char *magick_restrict pixels)
1572 message[MagickPathExtent],
1579 assert(server_info->signature == MagickCoreSignature);
1581 assert(pixels != (
const unsigned char *) NULL);
1582 if (length > (MagickSizeType) MAGICK_SSIZE_MAX)
1586 (void) memcpy(p,&server_info->session_key,
sizeof(server_info->session_key));
1587 p+=(ptrdiff_t)
sizeof(server_info->session_key);
1588 (void) memcpy(p,®ion->width,
sizeof(region->width));
1589 p+=(ptrdiff_t)
sizeof(region->width);
1590 (void) memcpy(p,®ion->height,
sizeof(region->height));
1591 p+=(ptrdiff_t)
sizeof(region->height);
1592 (void) memcpy(p,®ion->x,
sizeof(region->x));
1593 p+=(ptrdiff_t)
sizeof(region->x);
1594 (void) memcpy(p,®ion->y,
sizeof(region->y));
1595 p+=(ptrdiff_t)
sizeof(region->y);
1596 (void) memcpy(p,&length,
sizeof(length));
1597 p+=(ptrdiff_t)
sizeof(length);
1598 count=dpc_send(server_info->file,(MagickSizeType) (p-message),message);
1599 if (count != (MagickOffsetType) (p-message))
1601 return(dpc_send(server_info->file,length,pixels));