2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % DDDD IIIII SSSSS TTTTT RRRR IIIII BBBB U U TTTTT EEEEE %
6 % D D I SS T R R I B B U U T E %
7 % D D I SSS T RRRR I BBBB U U T EEE %
8 % D D I SS T R R I B B U U T E %
9 % DDDDA IIIII SSSSS T R R IIIII BBBB UUU T EEEEE %
11 % CCCC AAA CCCC H H EEEEE %
13 % C AAAAA C HHHHH EEE %
15 % CCCC A A CCCC H H EEEEE %
18 % MagickCore Distributed Pixel Cache Methods %
25 % Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
31 % http://www.imagemagick.org/script/license.php %
33 % Unless required by applicable law or agreed to in writing, software %
34 % distributed under the License is distributed on an "AS IS" BASIS, %
35 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36 % See the License for the specific language governing permissions and %
37 % limitations under the License. %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 % A distributed pixel cache is an extension of the traditional pixel cache
42 % available on a single host. The distributed pixel cache may span multiple
43 % servers so that it can grow in size and transactional capacity to support
44 % very large images. Start up the pixel cache server on one or more machines.
45 % When you read or operate on an image and the local pixel cache resources are
46 % exhausted, ImageMagick contacts one or more of these remote pixel servers to
47 % store or retrieve pixels.
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/list.h"
64 #include "MagickCore/locale_.h"
65 #include "MagickCore/memory_.h"
66 #include "MagickCore/nt-base-private.h"
67 #include "MagickCore/pixel.h"
68 #include "MagickCore/policy.h"
69 #include "MagickCore/random_.h"
70 #include "MagickCore/registry.h"
71 #include "MagickCore/splay-tree.h"
72 #include "MagickCore/string_.h"
73 #include "MagickCore/string-private.h"
74 #include "MagickCore/version.h"
75 #include "MagickCore/version-private.h"
76 #if defined(MAGICKCORE_HAVE_SOCKET)
77 #include <netinet/in.h>
79 #include <sys/socket.h>
80 #include <arpa/inet.h>
84 #define send(file,buffer,length,flags) 0
85 #define recv(file,buffer,length,flags) 0
91 #define DPCHostname "127.0.0.1"
92 #define DPCPendingConnections 10
94 #define DPCSessionKeyLength 8
96 # define MSG_NOSIGNAL 0
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 + A c q u i r e D i s t r i b u t e C a c h e I n f o %
108 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 % AcquireDistributeCacheInfo() allocates the DistributeCacheInfo structure.
112 % The format of the AcquireDistributeCacheInfo method is:
114 % DistributeCacheInfo *AcquireDistributeCacheInfo(ExceptionInfo *exception)
116 % A description of each parameter follows:
118 % o exception: return any errors or warnings in this structure.
122 static inline MagickSizeType MagickMin(const MagickSizeType x,
123 const MagickSizeType y)
130 static inline MagickOffsetType dpc_read(int file,const MagickSizeType length,
131 unsigned char *restrict message)
133 register MagickOffsetType
140 for (i=0; i < (MagickOffsetType) length; i+=count)
142 count=recv(file,message+i,(size_t) MagickMin(length-i,(MagickSizeType)
154 static int ConnectPixelCacheServer(const char *hostname,const int port,
155 size_t *session_key,ExceptionInfo *exception)
157 #if defined(MAGICKCORE_HAVE_SOCKET)
159 service[MaxTextExtent];
176 secret[MaxTextExtent];
179 Connect to distributed pixel cache and get session key.
182 shared_secret=GetPolicyValue("shared-secret");
183 if (shared_secret == (const char *) NULL)
185 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
186 "DistributedPixelCache","'%s'","shared secret expected");
189 (void) ResetMagickMemory(&hint,0,sizeof(hint));
190 hint.ai_family=AF_INET;
191 hint.ai_socktype=SOCK_STREAM;
192 hint.ai_flags=AI_PASSIVE;
193 (void) FormatLocaleString(service,MaxTextExtent,"%d",port);
194 status=getaddrinfo(hostname,service,&hint,&result);
197 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
198 "DistributedPixelCache","'%s'",hostname);
201 client_socket=socket(result->ai_family,result->ai_socktype,
202 result->ai_protocol);
203 if (client_socket == -1)
205 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
206 "DistributedPixelCache","'%s'",hostname);
209 status=connect(client_socket,result->ai_addr,result->ai_addrlen);
212 (void) ThrowMagickException(exception,GetMagickModule(),CacheError,
213 "DistributedPixelCache","'%s'",hostname);
216 count=recv(client_socket,secret,MaxTextExtent,0);
222 nonce=AcquireStringInfo(count);
223 (void) memcpy(GetStringInfoDatum(nonce),secret,(size_t) count);
224 *session_key=GetMagickSignature(nonce);
225 nonce=DestroyStringInfo(nonce);
227 if (*session_key == 0)
229 close(client_socket);
232 return(client_socket);
234 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
235 "DelegateLibrarySupportNotBuiltIn","distributed pixel cache");
240 static char *GetHostname(int *port,ExceptionInfo *exception)
257 Parse host list (e.g. 192.168.100.1:6668,192.168.100.2:6668).
259 hosts=(char *) GetImageRegistry(StringRegistryType,"cache:hosts",
261 if (hosts == (char *) NULL)
264 return(AcquireString(DPCHostname));
266 (void) SubstituteString(&hosts,","," ");
267 hostlist=StringToArgv(hosts,&argc);
268 hosts=DestroyString(hosts);
269 if (hostlist == (char **) NULL)
272 return(AcquireString(DPCHostname));
274 hosts=AcquireString(hostlist[(id++ % (argc-1))+1]);
275 for (i=0; i < (ssize_t) argc; i++)
276 hostlist[i]=DestroyString(hostlist[i]);
277 hostlist=(char **) RelinquishMagickMemory(hostlist);
278 (void) SubstituteString(&hosts,":"," ");
279 hostlist=StringToArgv(hosts,&argc);
280 if (hostlist == (char **) NULL)
283 return(AcquireString(DPCHostname));
285 host=AcquireString(hostlist[1]);
286 if (hostlist[2] == (char *) NULL)
289 *port=StringToLong(hostlist[2]);
290 for (i=0; i < (ssize_t) argc; i++)
291 hostlist[i]=DestroyString(hostlist[i]);
292 hostlist=(char **) RelinquishMagickMemory(hostlist);
296 MagickPrivate DistributeCacheInfo *AcquireDistributeCacheInfo(
297 ExceptionInfo *exception)
309 Connect to the distributed pixel cache server.
311 server_info=(DistributeCacheInfo *) AcquireMagickMemory(sizeof(*server_info));
312 if (server_info == (DistributeCacheInfo *) NULL)
313 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
314 (void) ResetMagickMemory(server_info,0,sizeof(*server_info));
315 server_info->signature=MagickSignature;
317 hostname=GetHostname(&server_info->port,exception);
319 server_info->file=ConnectPixelCacheServer(hostname,server_info->port,
320 &session_key,exception);
321 server_info->session_key=session_key;
322 (void) CopyMagickString(server_info->hostname,hostname,MaxTextExtent);
323 hostname=DestroyString(hostname);
324 if (server_info->file == -1)
325 server_info=DestroyDistributeCacheInfo(server_info);
330 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 + D e s t r o y D i s t r i b u t e C a c h e I n f o %
338 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
340 % DestroyDistributeCacheInfo() deallocates memory associated with an
341 % DistributeCacheInfo structure.
343 % The format of the DestroyDistributeCacheInfo method is:
345 % DistributeCacheInfo *DestroyDistributeCacheInfo(
346 % DistributeCacheInfo *server_info)
348 % A description of each parameter follows:
350 % o server_info: the distributed cache info.
353 MagickPrivate DistributeCacheInfo *DestroyDistributeCacheInfo(
354 DistributeCacheInfo *server_info)
356 assert(server_info != (DistributeCacheInfo *) NULL);
357 assert(server_info->signature == MagickSignature);
358 if (server_info->file > 0)
359 (void) close(server_info->file);
360 server_info->signature=(~MagickSignature);
361 server_info=(DistributeCacheInfo *) RelinquishMagickMemory(server_info);
366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370 + D i s t r i b u t e P i x e l C a c h e S e r v e r %
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
376 % DistributePixelCacheServer() waits on the specified port for commands to
377 % create, read, update, or destroy a pixel cache.
379 % The format of the DistributePixelCacheServer() method is:
381 % void DistributePixelCacheServer(const int port)
383 % A description of each parameter follows:
385 % o port: connect the distributed pixel cache at this port.
387 % o exception: return any errors or warnings in this structure.
391 static MagickBooleanType DestroyDistributeCache(SplayTreeInfo *registry,
392 int file,const size_t session_key)
395 Destroy distributed pixel cache.
397 return(DeleteNodeFromSplayTree(registry,(const void *) session_key));
400 static inline MagickOffsetType dpc_send(int file,const MagickSizeType length,
401 const unsigned char *restrict message)
406 register MagickOffsetType
410 Ensure a complete message is sent.
413 for (i=0; i < (MagickOffsetType) length; i+=count)
415 count=(MagickOffsetType) send(file,message+i,(size_t) MagickMin(length-i,
416 (MagickSizeType) SSIZE_MAX),MSG_NOSIGNAL);
427 static MagickBooleanType OpenDistributeCache(SplayTreeInfo *registry,
428 int file,const size_t session_key,ExceptionInfo *exception)
442 register unsigned char
446 message[MaxTextExtent];
449 Open distributed pixel cache.
451 image=AcquireImage((ImageInfo *) NULL,exception);
452 if (image == (Image *) NULL)
454 length=sizeof(image->storage_class)+sizeof(image->colorspace)+
455 sizeof(image->alpha_trait)+sizeof(image->mask)+sizeof(image->columns)+
456 sizeof(image->rows)+sizeof(image->number_channels)+MaxPixelChannels*
457 sizeof(*image->channel_map)+sizeof(image->metacontent_extent);
458 count=dpc_read(file,length,message);
459 if (count != (MagickOffsetType) length)
462 Deserialize the image attributes.
465 (void) memcpy(&image->storage_class,p,sizeof(image->storage_class));
466 p+=sizeof(image->storage_class);
467 (void) memcpy(&image->colorspace,p,sizeof(image->colorspace));
468 p+=sizeof(image->colorspace);
469 (void) memcpy(&image->alpha_trait,p,sizeof(image->alpha_trait));
470 p+=sizeof(image->alpha_trait);
471 (void) memcpy(&image->mask,p,sizeof(image->mask));
472 p+=sizeof(image->mask);
473 (void) memcpy(&image->columns,p,sizeof(image->columns));
474 p+=sizeof(image->columns);
475 (void) memcpy(&image->rows,p,sizeof(image->rows));
476 p+=sizeof(image->rows);
477 (void) memcpy(&image->number_channels,p,sizeof(image->number_channels));
478 p+=sizeof(image->number_channels);
479 (void) memcpy(image->channel_map,p,MaxPixelChannels*
480 sizeof(*image->channel_map));
481 p+=MaxPixelChannels*sizeof(*image->channel_map);
482 (void) memcpy(&image->metacontent_extent,p,sizeof(image->metacontent_extent));
483 p+=sizeof(image->metacontent_extent);
484 if (SyncImagePixelCache(image,exception) == MagickFalse)
486 status=AddValueToSplayTree(registry,(const void *) session_key,image);
490 static MagickBooleanType ReadDistributeCacheMetacontent(SplayTreeInfo *registry,
491 int file,const size_t session_key,ExceptionInfo *exception)
508 register const Quantum
511 register unsigned char
515 message[MaxTextExtent];
518 Read distributed pixel cache metacontent.
520 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
521 if (image == (Image *) NULL)
523 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
524 sizeof(region.y)+sizeof(length);
525 count=dpc_read(file,length,message);
526 if (count != (MagickOffsetType) length)
529 (void) memcpy(®ion.width,q,sizeof(region.width));
530 q+=sizeof(region.width);
531 (void) memcpy(®ion.height,q,sizeof(region.height));
532 q+=sizeof(region.height);
533 (void) memcpy(®ion.x,q,sizeof(region.x));
535 (void) memcpy(®ion.y,q,sizeof(region.y));
537 (void) memcpy(&length,q,sizeof(length));
539 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
541 if (p == (const Quantum *) NULL)
543 metacontent=(const unsigned char *) GetVirtualMetacontent(image);
544 count=dpc_send(file,length,metacontent);
545 if (count != (MagickOffsetType) length)
550 static MagickBooleanType ReadDistributeCachePixels(SplayTreeInfo *registry,
551 int file,const size_t session_key,ExceptionInfo *exception)
565 register const Quantum
568 register unsigned char
572 message[MaxTextExtent];
575 Read distributed pixel cache pixels.
577 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
578 if (image == (Image *) NULL)
580 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
581 sizeof(region.y)+sizeof(length);
582 count=dpc_read(file,length,message);
583 if (count != (MagickOffsetType) length)
586 (void) memcpy(®ion.width,q,sizeof(region.width));
587 q+=sizeof(region.width);
588 (void) memcpy(®ion.height,q,sizeof(region.height));
589 q+=sizeof(region.height);
590 (void) memcpy(®ion.x,q,sizeof(region.x));
592 (void) memcpy(®ion.y,q,sizeof(region.y));
594 (void) memcpy(&length,q,sizeof(length));
596 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
598 if (p == (const Quantum *) NULL)
600 count=dpc_send(file,length,(unsigned char *) p);
601 if (count != (MagickOffsetType) length)
606 static void *RelinquishImageRegistry(void *image)
608 return((void *) DestroyImageList((Image *) image));
611 static MagickBooleanType WriteDistributeCacheMetacontent(
612 SplayTreeInfo *registry,int file,const size_t session_key,
613 ExceptionInfo *exception)
630 register unsigned char
634 message[MaxTextExtent],
638 Write distributed pixel cache metacontent.
640 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
641 if (image == (Image *) NULL)
643 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
644 sizeof(region.y)+sizeof(length);
645 count=dpc_read(file,length,message);
646 if (count != (MagickOffsetType) length)
649 (void) memcpy(®ion.width,p,sizeof(region.width));
650 p+=sizeof(region.width);
651 (void) memcpy(®ion.height,p,sizeof(region.height));
652 p+=sizeof(region.height);
653 (void) memcpy(®ion.x,p,sizeof(region.x));
655 (void) memcpy(®ion.y,p,sizeof(region.y));
657 (void) memcpy(&length,p,sizeof(length));
659 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
661 if (q == (Quantum *) NULL)
663 metacontent=(unsigned char *) GetAuthenticMetacontent(image);
664 count=dpc_read(file,length,metacontent);
665 if (count != (MagickOffsetType) length)
667 return(SyncAuthenticPixels(image,exception));
670 static MagickBooleanType WriteDistributeCachePixels(SplayTreeInfo *registry,
671 int file,const size_t session_key,ExceptionInfo *exception)
688 register unsigned char
692 message[MaxTextExtent];
695 Write distributed pixel cache pixels.
697 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
698 if (image == (Image *) NULL)
700 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
701 sizeof(region.y)+sizeof(length);
702 count=dpc_read(file,length,message);
703 if (count != (MagickOffsetType) length)
706 (void) memcpy(®ion.width,p,sizeof(region.width));
707 p+=sizeof(region.width);
708 (void) memcpy(®ion.height,p,sizeof(region.height));
709 p+=sizeof(region.height);
710 (void) memcpy(®ion.x,p,sizeof(region.x));
712 (void) memcpy(®ion.y,p,sizeof(region.y));
714 (void) memcpy(&length,p,sizeof(length));
716 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
718 if (q == (Quantum *) NULL)
720 count=dpc_read(file,length,(unsigned char *) q);
721 if (count != (MagickOffsetType) length)
723 return(SyncAuthenticPixels(image,exception));
726 static void *DistributePixelCacheClient(void *socket)
743 register unsigned char
761 session[2*MaxTextExtent];
764 Distributed pixel cache client.
766 shared_secret=GetPolicyValue("shared-secret");
767 if (shared_secret == (const char *) NULL)
768 ThrowFatalException(CacheFatalError,"shared secret expected");
770 (void) CopyMagickString((char *) p,shared_secret,MaxTextExtent);
771 p+=strlen(shared_secret);
772 random_info=AcquireRandomInfo();
773 secret=GetRandomKey(random_info,DPCSessionKeyLength);
774 (void) memcpy(p,GetStringInfoDatum(secret),DPCSessionKeyLength);
775 session_key=GetMagickSignature(secret);
776 random_info=DestroyRandomInfo(random_info);
777 exception=AcquireExceptionInfo();
778 registry=NewSplayTree((int (*)(const void *,const void *)) NULL,
779 (void *(*)(void *)) NULL,RelinquishImageRegistry);
780 client_socket=(*(int *) socket);
781 count=dpc_send(client_socket,DPCSessionKeyLength,GetStringInfoDatum(secret));
782 secret=DestroyStringInfo(secret);
785 count=dpc_read(client_socket,1,(unsigned char *) &command);
788 count=dpc_read(client_socket,sizeof(key),(unsigned char *) &key);
789 if ((count != (MagickOffsetType) sizeof(key)) || (key != session_key))
796 status=OpenDistributeCache(registry,client_socket,session_key,
798 count=dpc_send(client_socket,sizeof(status),(unsigned char *) &status);
803 status=ReadDistributeCachePixels(registry,client_socket,session_key,
809 status=ReadDistributeCacheMetacontent(registry,client_socket,
810 session_key,exception);
815 status=WriteDistributeCachePixels(registry,client_socket,session_key,
821 status=WriteDistributeCacheMetacontent(registry,client_socket,
822 session_key,exception);
827 status=DestroyDistributeCache(registry,client_socket,session_key);
833 if (status == MagickFalse)
838 count=dpc_send(client_socket,sizeof(status),(unsigned char *) &status);
839 (void) close(client_socket);
840 exception=DestroyExceptionInfo(exception);
841 registry=DestroySplayTree(registry);
842 return((void *) NULL);
845 MagickExport void DistributePixelCacheServer(const int port,
846 ExceptionInfo *exception)
848 #if defined(MAGICKCORE_HAVE_SOCKET)
850 service[MaxTextExtent];
862 register struct addrinfo
873 Launch distributed pixel cache server.
875 (void) ResetMagickMemory(&hint,0,sizeof(hint));
876 hint.ai_family=AF_INET;
877 hint.ai_socktype=SOCK_STREAM;
878 hint.ai_flags=AI_PASSIVE;
879 (void) FormatLocaleString(service,MaxTextExtent,"%d",port);
880 status=getaddrinfo((const char *) NULL,service,&hint,&result);
882 ThrowFatalException(CacheFatalError,"UnableToListen");
884 for (p=result; p != (struct addrinfo *) NULL; p=p->ai_next)
889 server_socket=socket(p->ai_family,p->ai_socktype,p->ai_protocol);
890 if (server_socket == -1)
893 status=setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,&one,(socklen_t)
897 status=bind(server_socket,p->ai_addr,p->ai_addrlen);
900 (void) close(status);
905 if (p == (struct addrinfo *) NULL)
906 ThrowFatalException(CacheFatalError,"UnableToBind");
907 freeaddrinfo(result);
908 status=listen(server_socket,DPCPendingConnections);
910 ThrowFatalException(CacheFatalError,"UnableToListen");
911 pthread_attr_init(&attributes);
920 length=(socklen_t) sizeof(address);
921 client_socket=accept(server_socket,(struct sockaddr *) &address,&length);
922 if (client_socket == -1)
923 ThrowFatalException(CacheFatalError,"UnableToEstablishConnection");
924 status=pthread_create(&threads,&attributes,DistributePixelCacheClient,
925 (void *) &client_socket);
927 ThrowFatalException(CacheFatalError,"UnableToCreateClientThread");
929 (void) close(server_socket);
931 ThrowFatalException(MissingDelegateError,"distributed pixel cache");
936 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
940 + G e t D i s t r i b u t e C a c h e F i l e %
944 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
946 % GetDistributeCacheFile() returns the file associated with this
947 % DistributeCacheInfo structure.
949 % The format of the GetDistributeCacheFile method is:
951 % int GetDistributeCacheFile(const DistributeCacheInfo *server_info)
953 % A description of each parameter follows:
955 % o server_info: the distributed cache info.
958 MagickPrivate int GetDistributeCacheFile(const DistributeCacheInfo *server_info)
960 assert(server_info != (DistributeCacheInfo *) NULL);
961 assert(server_info->signature == MagickSignature);
962 return(server_info->file);
966 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
970 + G e t D i s t r i b u t e C a c h e H o s t n a m e %
974 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 % GetDistributeCacheHostname() returns the hostname associated with this
977 % DistributeCacheInfo structure.
979 % The format of the GetDistributeCacheHostname method is:
981 % const char *GetDistributeCacheHostname(
982 % const DistributeCacheInfo *server_info)
984 % A description of each parameter follows:
986 % o server_info: the distributed cache info.
989 MagickPrivate const char *GetDistributeCacheHostname(
990 const DistributeCacheInfo *server_info)
992 assert(server_info != (DistributeCacheInfo *) NULL);
993 assert(server_info->signature == MagickSignature);
994 return(server_info->hostname);
998 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1002 + G e t D i s t r i b u t e C a c h e P o r t %
1006 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008 % GetDistributeCachePort() returns the port associated with this
1009 % DistributeCacheInfo structure.
1011 % The format of the GetDistributeCachePort method is:
1013 % int GetDistributeCachePort(const DistributeCacheInfo *server_info)
1015 % A description of each parameter follows:
1017 % o server_info: the distributed cache info.
1020 MagickPrivate int GetDistributeCachePort(const DistributeCacheInfo *server_info)
1022 assert(server_info != (DistributeCacheInfo *) NULL);
1023 assert(server_info->signature == MagickSignature);
1024 return(server_info->port);
1028 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1032 + O p e n D i s t r i b u t e P i x e l C a c h e %
1036 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1038 % OpenDistributePixelCache() opens a pixel cache on a remote server.
1040 % The format of the OpenDistributePixelCache method is:
1042 % MagickBooleanType *OpenDistributePixelCache(
1043 % DistributeCacheInfo *server_info,Image *image)
1045 % A description of each parameter follows:
1047 % o server_info: the distributed cache info.
1049 % o image: the image.
1052 MagickPrivate MagickBooleanType OpenDistributePixelCache(
1053 DistributeCacheInfo *server_info,Image *image)
1061 register unsigned char
1065 message[MaxTextExtent];
1068 Open distributed pixel cache.
1070 assert(server_info != (DistributeCacheInfo *) NULL);
1071 assert(server_info->signature == MagickSignature);
1072 assert(image != (Image *) NULL);
1073 assert(image->signature == MagickSignature);
1075 *p++='o'; /* open */
1077 Serialize image attributes (see ValidatePixelCacheMorphology()).
1079 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1080 p+=sizeof(server_info->session_key);
1081 (void) memcpy(p,&image->storage_class,sizeof(image->storage_class));
1082 p+=sizeof(image->storage_class);
1083 (void) memcpy(p,&image->colorspace,sizeof(image->colorspace));
1084 p+=sizeof(image->colorspace);
1085 (void) memcpy(p,&image->alpha_trait,sizeof(image->alpha_trait));
1086 p+=sizeof(image->alpha_trait);
1087 (void) memcpy(p,&image->mask,sizeof(image->mask));
1088 p+=sizeof(image->mask);
1089 (void) memcpy(p,&image->columns,sizeof(image->columns));
1090 p+=sizeof(image->columns);
1091 (void) memcpy(p,&image->rows,sizeof(image->rows));
1092 p+=sizeof(image->rows);
1093 (void) memcpy(p,&image->number_channels,sizeof(image->number_channels));
1094 p+=sizeof(image->number_channels);
1095 (void) memcpy(p,image->channel_map,MaxPixelChannels*
1096 sizeof(*image->channel_map));
1097 p+=MaxPixelChannels*sizeof(*image->channel_map);
1098 (void) memcpy(p,&image->metacontent_extent,sizeof(image->metacontent_extent));
1099 p+=sizeof(image->metacontent_extent);
1100 count=dpc_send(server_info->file,p-message,message);
1101 if (count != (MagickOffsetType) (p-message))
1102 return(MagickFalse);
1104 count=dpc_read(server_info->file,sizeof(status),(unsigned char *) &status);
1105 if (count != (MagickOffsetType) sizeof(status))
1106 return(MagickFalse);
1111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1115 + R e a d D i s t r i b u t e P i x e l C a c h e M e t a c o n t e n t %
1119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1121 % ReadDistributePixelCacheMetacontents() reads metacontent from the specified
1122 % region of the distributed pixel cache.
1124 % The format of the ReadDistributePixelCacheMetacontents method is:
1126 % MagickOffsetType ReadDistributePixelCacheMetacontents(
1127 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1128 % const MagickSizeType length,unsigned char *metacontent)
1130 % A description of each parameter follows:
1132 % o server_info: the distributed cache info.
1134 % o image: the image.
1136 % o region: read the metacontent from this region of the image.
1138 % o length: the length in bytes of the metacontent.
1140 % o metacontent: read these metacontent from the pixel cache.
1143 MagickPrivate MagickOffsetType ReadDistributePixelCacheMetacontent(
1144 DistributeCacheInfo *server_info,const RectangleInfo *region,
1145 const MagickSizeType length,unsigned char *metacontent)
1150 register unsigned char
1154 message[MaxTextExtent];
1157 Read distributed pixel cache metacontent.
1159 assert(server_info != (DistributeCacheInfo *) NULL);
1160 assert(server_info->signature == MagickSignature);
1161 assert(region != (RectangleInfo *) NULL);
1162 assert(metacontent != (unsigned char *) NULL);
1163 if (length > (MagickSizeType) SSIZE_MAX)
1167 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1168 p+=sizeof(server_info->session_key);
1169 (void) memcpy(p,®ion->width,sizeof(region->width));
1170 p+=sizeof(region->width);
1171 (void) memcpy(p,®ion->height,sizeof(region->height));
1172 p+=sizeof(region->height);
1173 (void) memcpy(p,®ion->x,sizeof(region->x));
1174 p+=sizeof(region->x);
1175 (void) memcpy(p,®ion->y,sizeof(region->y));
1176 p+=sizeof(region->y);
1177 (void) memcpy(p,&length,sizeof(length));
1179 count=dpc_send(server_info->file,p-message,message);
1180 if (count != (MagickOffsetType) (p-message))
1182 return(dpc_read(server_info->file,length,metacontent));
1186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1190 + R e a d D i s t r i b u t e P i x e l C a c h e P i x e l s %
1194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196 % ReadDistributePixelCachePixels() reads pixels from the specified region of
1197 % the distributed pixel cache.
1199 % The format of the ReadDistributePixelCachePixels method is:
1201 % MagickOffsetType ReadDistributePixelCachePixels(
1202 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1203 % const MagickSizeType length,unsigned char *pixels)
1205 % A description of each parameter follows:
1207 % o server_info: the distributed cache info.
1209 % o image: the image.
1211 % o region: read the pixels from this region of the image.
1213 % o length: the length in bytes of the pixels.
1215 % o pixels: read these pixels from the pixel cache.
1218 MagickPrivate MagickOffsetType ReadDistributePixelCachePixels(
1219 DistributeCacheInfo *server_info,const RectangleInfo *region,
1220 const MagickSizeType length,unsigned char *pixels)
1225 register unsigned char
1229 message[MaxTextExtent];
1232 Read distributed pixel cache pixels.
1234 assert(server_info != (DistributeCacheInfo *) NULL);
1235 assert(server_info->signature == MagickSignature);
1236 assert(region != (RectangleInfo *) NULL);
1237 assert(pixels != (unsigned char *) NULL);
1238 if (length > (MagickSizeType) SSIZE_MAX)
1242 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1243 p+=sizeof(server_info->session_key);
1244 (void) memcpy(p,®ion->width,sizeof(region->width));
1245 p+=sizeof(region->width);
1246 (void) memcpy(p,®ion->height,sizeof(region->height));
1247 p+=sizeof(region->height);
1248 (void) memcpy(p,®ion->x,sizeof(region->x));
1249 p+=sizeof(region->x);
1250 (void) memcpy(p,®ion->y,sizeof(region->y));
1251 p+=sizeof(region->y);
1252 (void) memcpy(p,&length,sizeof(length));
1254 count=dpc_send(server_info->file,p-message,message);
1255 if (count != (MagickOffsetType) (p-message))
1257 return(dpc_read(server_info->file,length,pixels));
1261 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1265 + R e l i n q u i s h D i s t r i b u t e P i x e l C a c h e %
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1271 % RelinquishDistributePixelCache() frees resources acquired with
1272 % OpenDistributePixelCache().
1274 % The format of the RelinquishDistributePixelCache method is:
1276 % MagickBooleanType RelinquishDistributePixelCache(
1277 % DistributeCacheInfo *server_info)
1279 % A description of each parameter follows:
1281 % o server_info: the distributed cache info.
1284 MagickPrivate MagickBooleanType RelinquishDistributePixelCache(
1285 DistributeCacheInfo *server_info)
1293 register unsigned char
1297 message[MaxTextExtent];
1300 Delete distributed pixel cache.
1302 assert(server_info != (DistributeCacheInfo *) NULL);
1303 assert(server_info->signature == MagickSignature);
1306 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1307 p+=sizeof(server_info->session_key);
1308 count=dpc_send(server_info->file,p-message,message);
1309 if (count != (MagickOffsetType) (p-message))
1310 return(MagickFalse);
1311 count=dpc_read(server_info->file,sizeof(status),(unsigned char *) &status);
1312 if (count != (MagickOffsetType) sizeof(status))
1313 return(MagickFalse);
1318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1322 + W r i t e D i s t r i b u t e P i x e l C a c h e M e t a c o n t e n t %
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328 % WriteDistributePixelCacheMetacontents() writes image metacontent to the
1329 % specified region of the distributed pixel cache.
1331 % The format of the WriteDistributePixelCacheMetacontents method is:
1333 % MagickOffsetType WriteDistributePixelCacheMetacontents(
1334 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1335 % const MagickSizeType length,const unsigned char *metacontent)
1337 % A description of each parameter follows:
1339 % o server_info: the distributed cache info.
1341 % o image: the image.
1343 % o region: write the metacontent to this region of the image.
1345 % o length: the length in bytes of the metacontent.
1347 % o metacontent: write these metacontent to the pixel cache.
1350 MagickPrivate MagickOffsetType WriteDistributePixelCacheMetacontent(
1351 DistributeCacheInfo *server_info,const RectangleInfo *region,
1352 const MagickSizeType length,const unsigned char *metacontent)
1357 register unsigned char
1361 message[MaxTextExtent];
1364 Write distributed pixel cache metacontent.
1366 assert(server_info != (DistributeCacheInfo *) NULL);
1367 assert(server_info->signature == MagickSignature);
1368 assert(region != (RectangleInfo *) NULL);
1369 assert(metacontent != (unsigned char *) NULL);
1370 if (length > (MagickSizeType) SSIZE_MAX)
1374 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1375 p+=sizeof(server_info->session_key);
1376 (void) memcpy(p,®ion->width,sizeof(region->width));
1377 p+=sizeof(region->width);
1378 (void) memcpy(p,®ion->height,sizeof(region->height));
1379 p+=sizeof(region->height);
1380 (void) memcpy(p,®ion->x,sizeof(region->x));
1381 p+=sizeof(region->x);
1382 (void) memcpy(p,®ion->y,sizeof(region->y));
1383 p+=sizeof(region->y);
1384 (void) memcpy(p,&length,sizeof(length));
1386 count=dpc_send(server_info->file,p-message,message);
1387 if (count != (MagickOffsetType) (p-message))
1389 return(dpc_send(server_info->file,length,metacontent));
1393 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1397 + W r i t e D i s t r i b u t e P i x e l C a c h e P i x e l s %
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1403 % WriteDistributePixelCachePixels() writes image pixels to the specified
1404 % region of the distributed pixel cache.
1406 % The format of the WriteDistributePixelCachePixels method is:
1408 % MagickBooleanType WriteDistributePixelCachePixels(
1409 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1410 % const MagickSizeType length,const unsigned char *pixels)
1412 % A description of each parameter follows:
1414 % o server_info: the distributed cache info.
1416 % o image: the image.
1418 % o region: write the pixels to this region of the image.
1420 % o length: the length in bytes of the pixels.
1422 % o pixels: write these pixels to the pixel cache.
1425 MagickPrivate MagickOffsetType WriteDistributePixelCachePixels(
1426 DistributeCacheInfo *server_info,const RectangleInfo *region,
1427 const MagickSizeType length,const unsigned char *pixels)
1432 register unsigned char
1436 message[MaxTextExtent];
1439 Write distributed pixel cache pixels.
1441 assert(server_info != (DistributeCacheInfo *) NULL);
1442 assert(server_info->signature == MagickSignature);
1443 assert(region != (RectangleInfo *) NULL);
1444 assert(pixels != (const unsigned char *) NULL);
1445 if (length > (MagickSizeType) SSIZE_MAX)
1449 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1450 p+=sizeof(server_info->session_key);
1451 (void) memcpy(p,®ion->width,sizeof(region->width));
1452 p+=sizeof(region->width);
1453 (void) memcpy(p,®ion->height,sizeof(region->height));
1454 p+=sizeof(region->height);
1455 (void) memcpy(p,®ion->x,sizeof(region->x));
1456 p+=sizeof(region->x);
1457 (void) memcpy(p,®ion->y,sizeof(region->y));
1458 p+=sizeof(region->y);
1459 (void) memcpy(p,&length,sizeof(length));
1461 count=dpc_send(server_info->file,p-message,message);
1462 if (count != (MagickOffsetType) (p-message))
1464 return(dpc_send(server_info->file,length,pixels));