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) && defined(MAGICKCORE_THREAD_SUPPORT)
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) && defined(MAGICKCORE_THREAD_SUPPORT)
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.
398 return(DeleteNodeFromSplayTree(registry,(const void *) session_key));
401 static inline MagickOffsetType dpc_send(int file,const MagickSizeType length,
402 const unsigned char *restrict message)
407 register MagickOffsetType
411 Ensure a complete message is sent.
414 for (i=0; i < (MagickOffsetType) length; i+=count)
416 count=(MagickOffsetType) send(file,message+i,(size_t) MagickMin(length-i,
417 (MagickSizeType) SSIZE_MAX),MSG_NOSIGNAL);
428 static MagickBooleanType OpenDistributeCache(SplayTreeInfo *registry,
429 int file,const size_t session_key,ExceptionInfo *exception)
443 register unsigned char
447 message[MaxTextExtent];
450 Open distributed pixel cache.
452 image=AcquireImage((ImageInfo *) NULL,exception);
453 if (image == (Image *) NULL)
455 length=sizeof(image->storage_class)+sizeof(image->colorspace)+
456 sizeof(image->alpha_trait)+sizeof(image->read_mask)+
457 sizeof(image->write_mask)+sizeof(image->columns)+sizeof(image->rows)+
458 sizeof(image->number_channels)+MaxPixelChannels*sizeof(*image->channel_map)+
459 sizeof(image->metacontent_extent);
460 count=dpc_read(file,length,message);
461 if (count != (MagickOffsetType) length)
464 Deserialize the image attributes.
467 (void) memcpy(&image->storage_class,p,sizeof(image->storage_class));
468 p+=sizeof(image->storage_class);
469 (void) memcpy(&image->colorspace,p,sizeof(image->colorspace));
470 p+=sizeof(image->colorspace);
471 (void) memcpy(&image->alpha_trait,p,sizeof(image->alpha_trait));
472 p+=sizeof(image->alpha_trait);
473 (void) memcpy(&image->read_mask,p,sizeof(image->read_mask));
474 p+=sizeof(image->read_mask);
475 (void) memcpy(&image->write_mask,p,sizeof(image->write_mask));
476 p+=sizeof(image->write_mask);
477 (void) memcpy(&image->columns,p,sizeof(image->columns));
478 p+=sizeof(image->columns);
479 (void) memcpy(&image->rows,p,sizeof(image->rows));
480 p+=sizeof(image->rows);
481 (void) memcpy(&image->number_channels,p,sizeof(image->number_channels));
482 p+=sizeof(image->number_channels);
483 (void) memcpy(image->channel_map,p,MaxPixelChannels*
484 sizeof(*image->channel_map));
485 p+=MaxPixelChannels*sizeof(*image->channel_map);
486 (void) memcpy(&image->metacontent_extent,p,sizeof(image->metacontent_extent));
487 p+=sizeof(image->metacontent_extent);
488 if (SyncImagePixelCache(image,exception) == MagickFalse)
490 status=AddValueToSplayTree(registry,(const void *) session_key,image);
494 static MagickBooleanType ReadDistributeCacheMetacontent(SplayTreeInfo *registry,
495 int file,const size_t session_key,ExceptionInfo *exception)
512 register const Quantum
515 register unsigned char
519 message[MaxTextExtent];
522 Read distributed pixel cache metacontent.
524 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
525 if (image == (Image *) NULL)
527 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
528 sizeof(region.y)+sizeof(length);
529 count=dpc_read(file,length,message);
530 if (count != (MagickOffsetType) length)
533 (void) memcpy(®ion.width,q,sizeof(region.width));
534 q+=sizeof(region.width);
535 (void) memcpy(®ion.height,q,sizeof(region.height));
536 q+=sizeof(region.height);
537 (void) memcpy(®ion.x,q,sizeof(region.x));
539 (void) memcpy(®ion.y,q,sizeof(region.y));
541 (void) memcpy(&length,q,sizeof(length));
543 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
545 if (p == (const Quantum *) NULL)
547 metacontent=(const unsigned char *) GetVirtualMetacontent(image);
548 count=dpc_send(file,length,metacontent);
549 if (count != (MagickOffsetType) length)
554 static MagickBooleanType ReadDistributeCachePixels(SplayTreeInfo *registry,
555 int file,const size_t session_key,ExceptionInfo *exception)
569 register const Quantum
572 register unsigned char
576 message[MaxTextExtent];
579 Read distributed pixel cache pixels.
581 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
582 if (image == (Image *) NULL)
584 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
585 sizeof(region.y)+sizeof(length);
586 count=dpc_read(file,length,message);
587 if (count != (MagickOffsetType) length)
590 (void) memcpy(®ion.width,q,sizeof(region.width));
591 q+=sizeof(region.width);
592 (void) memcpy(®ion.height,q,sizeof(region.height));
593 q+=sizeof(region.height);
594 (void) memcpy(®ion.x,q,sizeof(region.x));
596 (void) memcpy(®ion.y,q,sizeof(region.y));
598 (void) memcpy(&length,q,sizeof(length));
600 p=GetVirtualPixels(image,region.x,region.y,region.width,region.height,
602 if (p == (const Quantum *) NULL)
604 count=dpc_send(file,length,(unsigned char *) p);
605 if (count != (MagickOffsetType) length)
610 static void *RelinquishImageRegistry(void *image)
612 return((void *) DestroyImageList((Image *) image));
615 static MagickBooleanType WriteDistributeCacheMetacontent(
616 SplayTreeInfo *registry,int file,const size_t session_key,
617 ExceptionInfo *exception)
634 register unsigned char
638 message[MaxTextExtent],
642 Write distributed pixel cache metacontent.
644 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
645 if (image == (Image *) NULL)
647 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
648 sizeof(region.y)+sizeof(length);
649 count=dpc_read(file,length,message);
650 if (count != (MagickOffsetType) length)
653 (void) memcpy(®ion.width,p,sizeof(region.width));
654 p+=sizeof(region.width);
655 (void) memcpy(®ion.height,p,sizeof(region.height));
656 p+=sizeof(region.height);
657 (void) memcpy(®ion.x,p,sizeof(region.x));
659 (void) memcpy(®ion.y,p,sizeof(region.y));
661 (void) memcpy(&length,p,sizeof(length));
663 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
665 if (q == (Quantum *) NULL)
667 metacontent=(unsigned char *) GetAuthenticMetacontent(image);
668 count=dpc_read(file,length,metacontent);
669 if (count != (MagickOffsetType) length)
671 return(SyncAuthenticPixels(image,exception));
674 static MagickBooleanType WriteDistributeCachePixels(SplayTreeInfo *registry,
675 int file,const size_t session_key,ExceptionInfo *exception)
692 register unsigned char
696 message[MaxTextExtent];
699 Write distributed pixel cache pixels.
701 image=(Image *) GetValueFromSplayTree(registry,(const void *) session_key);
702 if (image == (Image *) NULL)
704 length=sizeof(region.width)+sizeof(region.height)+sizeof(region.x)+
705 sizeof(region.y)+sizeof(length);
706 count=dpc_read(file,length,message);
707 if (count != (MagickOffsetType) length)
710 (void) memcpy(®ion.width,p,sizeof(region.width));
711 p+=sizeof(region.width);
712 (void) memcpy(®ion.height,p,sizeof(region.height));
713 p+=sizeof(region.height);
714 (void) memcpy(®ion.x,p,sizeof(region.x));
716 (void) memcpy(®ion.y,p,sizeof(region.y));
718 (void) memcpy(&length,p,sizeof(length));
720 q=GetAuthenticPixels(image,region.x,region.y,region.width,region.height,
722 if (q == (Quantum *) NULL)
724 count=dpc_read(file,length,(unsigned char *) q);
725 if (count != (MagickOffsetType) length)
727 return(SyncAuthenticPixels(image,exception));
730 static void *DistributePixelCacheClient(void *socket)
747 register unsigned char
765 session[2*MaxTextExtent];
768 Distributed pixel cache client.
770 shared_secret=GetPolicyValue("shared-secret");
771 if (shared_secret == (const char *) NULL)
772 ThrowFatalException(CacheFatalError,"shared secret expected");
774 (void) CopyMagickString((char *) p,shared_secret,MaxTextExtent);
775 p+=strlen(shared_secret);
776 random_info=AcquireRandomInfo();
777 secret=GetRandomKey(random_info,DPCSessionKeyLength);
778 (void) memcpy(p,GetStringInfoDatum(secret),DPCSessionKeyLength);
779 session_key=GetMagickSignature(secret);
780 random_info=DestroyRandomInfo(random_info);
781 exception=AcquireExceptionInfo();
782 registry=NewSplayTree((int (*)(const void *,const void *)) NULL,
783 (void *(*)(void *)) NULL,RelinquishImageRegistry);
784 client_socket=(*(int *) socket);
785 count=dpc_send(client_socket,DPCSessionKeyLength,GetStringInfoDatum(secret));
786 secret=DestroyStringInfo(secret);
789 count=dpc_read(client_socket,1,(unsigned char *) &command);
792 count=dpc_read(client_socket,sizeof(key),(unsigned char *) &key);
793 if ((count != (MagickOffsetType) sizeof(key)) || (key != session_key))
800 status=OpenDistributeCache(registry,client_socket,session_key,
802 count=dpc_send(client_socket,sizeof(status),(unsigned char *) &status);
807 status=ReadDistributeCachePixels(registry,client_socket,session_key,
813 status=ReadDistributeCacheMetacontent(registry,client_socket,
814 session_key,exception);
819 status=WriteDistributeCachePixels(registry,client_socket,session_key,
825 status=WriteDistributeCacheMetacontent(registry,client_socket,
826 session_key,exception);
831 status=DestroyDistributeCache(registry,client_socket,session_key);
837 if (status == MagickFalse)
842 count=dpc_send(client_socket,sizeof(status),(unsigned char *) &status);
843 (void) close(client_socket);
844 exception=DestroyExceptionInfo(exception);
845 registry=DestroySplayTree(registry);
846 return((void *) NULL);
849 MagickExport void DistributePixelCacheServer(const int port,
850 ExceptionInfo *exception)
852 #if defined(MAGICKCORE_HAVE_SOCKET) && defined(MAGICKCORE_THREAD_SUPPORT)
854 service[MaxTextExtent];
866 register struct addrinfo
877 Launch distributed pixel cache server.
879 assert(exception != (ExceptionInfo *) NULL);
880 assert(exception->signature == MagickSignature);
881 (void) ResetMagickMemory(&hint,0,sizeof(hint));
882 hint.ai_family=AF_INET;
883 hint.ai_socktype=SOCK_STREAM;
884 hint.ai_flags=AI_PASSIVE;
885 (void) FormatLocaleString(service,MaxTextExtent,"%d",port);
886 status=getaddrinfo((const char *) NULL,service,&hint,&result);
888 ThrowFatalException(CacheFatalError,"UnableToListen");
890 for (p=result; p != (struct addrinfo *) NULL; p=p->ai_next)
895 server_socket=socket(p->ai_family,p->ai_socktype,p->ai_protocol);
896 if (server_socket == -1)
899 status=setsockopt(server_socket,SOL_SOCKET,SO_REUSEADDR,&one,(socklen_t)
903 status=bind(server_socket,p->ai_addr,p->ai_addrlen);
906 (void) close(status);
911 if (p == (struct addrinfo *) NULL)
912 ThrowFatalException(CacheFatalError,"UnableToBind");
913 freeaddrinfo(result);
914 status=listen(server_socket,DPCPendingConnections);
916 ThrowFatalException(CacheFatalError,"UnableToListen");
917 pthread_attr_init(&attributes);
926 length=(socklen_t) sizeof(address);
927 client_socket=accept(server_socket,(struct sockaddr *) &address,&length);
928 if (client_socket == -1)
929 ThrowFatalException(CacheFatalError,"UnableToEstablishConnection");
930 status=pthread_create(&threads,&attributes,DistributePixelCacheClient,
931 (void *) &client_socket);
933 ThrowFatalException(CacheFatalError,"UnableToCreateClientThread");
935 (void) close(server_socket);
937 ThrowFatalException(MissingDelegateError,"distributed pixel cache");
942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
946 + G e t D i s t r i b u t e C a c h e F i l e %
950 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
952 % GetDistributeCacheFile() returns the file associated with this
953 % DistributeCacheInfo structure.
955 % The format of the GetDistributeCacheFile method is:
957 % int GetDistributeCacheFile(const DistributeCacheInfo *server_info)
959 % A description of each parameter follows:
961 % o server_info: the distributed cache info.
964 MagickPrivate int GetDistributeCacheFile(const DistributeCacheInfo *server_info)
966 assert(server_info != (DistributeCacheInfo *) NULL);
967 assert(server_info->signature == MagickSignature);
968 return(server_info->file);
972 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
976 + 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 %
980 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
982 % GetDistributeCacheHostname() returns the hostname associated with this
983 % DistributeCacheInfo structure.
985 % The format of the GetDistributeCacheHostname method is:
987 % const char *GetDistributeCacheHostname(
988 % const DistributeCacheInfo *server_info)
990 % A description of each parameter follows:
992 % o server_info: the distributed cache info.
995 MagickPrivate const char *GetDistributeCacheHostname(
996 const DistributeCacheInfo *server_info)
998 assert(server_info != (DistributeCacheInfo *) NULL);
999 assert(server_info->signature == MagickSignature);
1000 return(server_info->hostname);
1004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1008 + G e t D i s t r i b u t e C a c h e P o r t %
1012 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1014 % GetDistributeCachePort() returns the port associated with this
1015 % DistributeCacheInfo structure.
1017 % The format of the GetDistributeCachePort method is:
1019 % int GetDistributeCachePort(const DistributeCacheInfo *server_info)
1021 % A description of each parameter follows:
1023 % o server_info: the distributed cache info.
1026 MagickPrivate int GetDistributeCachePort(const DistributeCacheInfo *server_info)
1028 assert(server_info != (DistributeCacheInfo *) NULL);
1029 assert(server_info->signature == MagickSignature);
1030 return(server_info->port);
1034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1038 + O p e n D i s t r i b u t e P i x e l C a c h e %
1042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 % OpenDistributePixelCache() opens a pixel cache on a remote server.
1046 % The format of the OpenDistributePixelCache method is:
1048 % MagickBooleanType *OpenDistributePixelCache(
1049 % DistributeCacheInfo *server_info,Image *image)
1051 % A description of each parameter follows:
1053 % o server_info: the distributed cache info.
1055 % o image: the image.
1058 MagickPrivate MagickBooleanType OpenDistributePixelCache(
1059 DistributeCacheInfo *server_info,Image *image)
1067 register unsigned char
1071 message[MaxTextExtent];
1074 Open distributed pixel cache.
1076 assert(server_info != (DistributeCacheInfo *) NULL);
1077 assert(server_info->signature == MagickSignature);
1078 assert(image != (Image *) NULL);
1079 assert(image->signature == MagickSignature);
1081 *p++='o'; /* open */
1083 Serialize image attributes (see ValidatePixelCacheMorphology()).
1085 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1086 p+=sizeof(server_info->session_key);
1087 (void) memcpy(p,&image->storage_class,sizeof(image->storage_class));
1088 p+=sizeof(image->storage_class);
1089 (void) memcpy(p,&image->colorspace,sizeof(image->colorspace));
1090 p+=sizeof(image->colorspace);
1091 (void) memcpy(p,&image->alpha_trait,sizeof(image->alpha_trait));
1092 p+=sizeof(image->alpha_trait);
1093 (void) memcpy(p,&image->read_mask,sizeof(image->read_mask));
1094 p+=sizeof(image->read_mask);
1095 (void) memcpy(p,&image->write_mask,sizeof(image->write_mask));
1096 p+=sizeof(image->write_mask);
1097 (void) memcpy(p,&image->columns,sizeof(image->columns));
1098 p+=sizeof(image->columns);
1099 (void) memcpy(p,&image->rows,sizeof(image->rows));
1100 p+=sizeof(image->rows);
1101 (void) memcpy(p,&image->number_channels,sizeof(image->number_channels));
1102 p+=sizeof(image->number_channels);
1103 (void) memcpy(p,image->channel_map,MaxPixelChannels*
1104 sizeof(*image->channel_map));
1105 p+=MaxPixelChannels*sizeof(*image->channel_map);
1106 (void) memcpy(p,&image->metacontent_extent,sizeof(image->metacontent_extent));
1107 p+=sizeof(image->metacontent_extent);
1108 count=dpc_send(server_info->file,p-message,message);
1109 if (count != (MagickOffsetType) (p-message))
1110 return(MagickFalse);
1112 count=dpc_read(server_info->file,sizeof(status),(unsigned char *) &status);
1113 if (count != (MagickOffsetType) sizeof(status))
1114 return(MagickFalse);
1119 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1123 + 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 %
1127 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1129 % ReadDistributePixelCacheMetacontents() reads metacontent from the specified
1130 % region of the distributed pixel cache.
1132 % The format of the ReadDistributePixelCacheMetacontents method is:
1134 % MagickOffsetType ReadDistributePixelCacheMetacontents(
1135 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1136 % const MagickSizeType length,unsigned char *metacontent)
1138 % A description of each parameter follows:
1140 % o server_info: the distributed cache info.
1142 % o image: the image.
1144 % o region: read the metacontent from this region of the image.
1146 % o length: the length in bytes of the metacontent.
1148 % o metacontent: read these metacontent from the pixel cache.
1151 MagickPrivate MagickOffsetType ReadDistributePixelCacheMetacontent(
1152 DistributeCacheInfo *server_info,const RectangleInfo *region,
1153 const MagickSizeType length,unsigned char *metacontent)
1158 register unsigned char
1162 message[MaxTextExtent];
1165 Read distributed pixel cache metacontent.
1167 assert(server_info != (DistributeCacheInfo *) NULL);
1168 assert(server_info->signature == MagickSignature);
1169 assert(region != (RectangleInfo *) NULL);
1170 assert(metacontent != (unsigned char *) NULL);
1171 if (length > (MagickSizeType) SSIZE_MAX)
1175 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1176 p+=sizeof(server_info->session_key);
1177 (void) memcpy(p,®ion->width,sizeof(region->width));
1178 p+=sizeof(region->width);
1179 (void) memcpy(p,®ion->height,sizeof(region->height));
1180 p+=sizeof(region->height);
1181 (void) memcpy(p,®ion->x,sizeof(region->x));
1182 p+=sizeof(region->x);
1183 (void) memcpy(p,®ion->y,sizeof(region->y));
1184 p+=sizeof(region->y);
1185 (void) memcpy(p,&length,sizeof(length));
1187 count=dpc_send(server_info->file,p-message,message);
1188 if (count != (MagickOffsetType) (p-message))
1190 return(dpc_read(server_info->file,length,metacontent));
1194 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198 + 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 %
1202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1204 % ReadDistributePixelCachePixels() reads pixels from the specified region of
1205 % the distributed pixel cache.
1207 % The format of the ReadDistributePixelCachePixels method is:
1209 % MagickOffsetType ReadDistributePixelCachePixels(
1210 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1211 % const MagickSizeType length,unsigned char *restrict pixels)
1213 % A description of each parameter follows:
1215 % o server_info: the distributed cache info.
1217 % o image: the image.
1219 % o region: read the pixels from this region of the image.
1221 % o length: the length in bytes of the pixels.
1223 % o pixels: read these pixels from the pixel cache.
1226 MagickPrivate MagickOffsetType ReadDistributePixelCachePixels(
1227 DistributeCacheInfo *server_info,const RectangleInfo *region,
1228 const MagickSizeType length,unsigned char *restrict pixels)
1233 register unsigned char
1237 message[MaxTextExtent];
1240 Read distributed pixel cache pixels.
1242 assert(server_info != (DistributeCacheInfo *) NULL);
1243 assert(server_info->signature == MagickSignature);
1244 assert(region != (RectangleInfo *) NULL);
1245 assert(pixels != (unsigned char *) NULL);
1246 if (length > (MagickSizeType) SSIZE_MAX)
1250 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1251 p+=sizeof(server_info->session_key);
1252 (void) memcpy(p,®ion->width,sizeof(region->width));
1253 p+=sizeof(region->width);
1254 (void) memcpy(p,®ion->height,sizeof(region->height));
1255 p+=sizeof(region->height);
1256 (void) memcpy(p,®ion->x,sizeof(region->x));
1257 p+=sizeof(region->x);
1258 (void) memcpy(p,®ion->y,sizeof(region->y));
1259 p+=sizeof(region->y);
1260 (void) memcpy(p,&length,sizeof(length));
1262 count=dpc_send(server_info->file,p-message,message);
1263 if (count != (MagickOffsetType) (p-message))
1265 return(dpc_read(server_info->file,length,pixels));
1269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1273 + 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 %
1277 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 % RelinquishDistributePixelCache() frees resources acquired with
1280 % OpenDistributePixelCache().
1282 % The format of the RelinquishDistributePixelCache method is:
1284 % MagickBooleanType RelinquishDistributePixelCache(
1285 % DistributeCacheInfo *server_info)
1287 % A description of each parameter follows:
1289 % o server_info: the distributed cache info.
1292 MagickPrivate MagickBooleanType RelinquishDistributePixelCache(
1293 DistributeCacheInfo *server_info)
1301 register unsigned char
1305 message[MaxTextExtent];
1308 Delete distributed pixel cache.
1310 assert(server_info != (DistributeCacheInfo *) NULL);
1311 assert(server_info->signature == MagickSignature);
1314 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1315 p+=sizeof(server_info->session_key);
1316 count=dpc_send(server_info->file,p-message,message);
1317 if (count != (MagickOffsetType) (p-message))
1318 return(MagickFalse);
1319 count=dpc_read(server_info->file,sizeof(status),(unsigned char *) &status);
1320 if (count != (MagickOffsetType) sizeof(status))
1321 return(MagickFalse);
1326 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1330 + 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 %
1334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1336 % WriteDistributePixelCacheMetacontents() writes image metacontent to the
1337 % specified region of the distributed pixel cache.
1339 % The format of the WriteDistributePixelCacheMetacontents method is:
1341 % MagickOffsetType WriteDistributePixelCacheMetacontents(
1342 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1343 % const MagickSizeType length,const unsigned char *metacontent)
1345 % A description of each parameter follows:
1347 % o server_info: the distributed cache info.
1349 % o image: the image.
1351 % o region: write the metacontent to this region of the image.
1353 % o length: the length in bytes of the metacontent.
1355 % o metacontent: write these metacontent to the pixel cache.
1358 MagickPrivate MagickOffsetType WriteDistributePixelCacheMetacontent(
1359 DistributeCacheInfo *server_info,const RectangleInfo *region,
1360 const MagickSizeType length,const unsigned char *metacontent)
1365 register unsigned char
1369 message[MaxTextExtent];
1372 Write distributed pixel cache metacontent.
1374 assert(server_info != (DistributeCacheInfo *) NULL);
1375 assert(server_info->signature == MagickSignature);
1376 assert(region != (RectangleInfo *) NULL);
1377 assert(metacontent != (unsigned char *) NULL);
1378 if (length > (MagickSizeType) SSIZE_MAX)
1382 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1383 p+=sizeof(server_info->session_key);
1384 (void) memcpy(p,®ion->width,sizeof(region->width));
1385 p+=sizeof(region->width);
1386 (void) memcpy(p,®ion->height,sizeof(region->height));
1387 p+=sizeof(region->height);
1388 (void) memcpy(p,®ion->x,sizeof(region->x));
1389 p+=sizeof(region->x);
1390 (void) memcpy(p,®ion->y,sizeof(region->y));
1391 p+=sizeof(region->y);
1392 (void) memcpy(p,&length,sizeof(length));
1394 count=dpc_send(server_info->file,p-message,message);
1395 if (count != (MagickOffsetType) (p-message))
1397 return(dpc_send(server_info->file,length,metacontent));
1401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1405 + 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 %
1409 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1411 % WriteDistributePixelCachePixels() writes image pixels to the specified
1412 % region of the distributed pixel cache.
1414 % The format of the WriteDistributePixelCachePixels method is:
1416 % MagickBooleanType WriteDistributePixelCachePixels(
1417 % DistributeCacheInfo *server_info,const RectangleInfo *region,
1418 % const MagickSizeType length,const unsigned char *restrict pixels)
1420 % A description of each parameter follows:
1422 % o server_info: the distributed cache info.
1424 % o image: the image.
1426 % o region: write the pixels to this region of the image.
1428 % o length: the length in bytes of the pixels.
1430 % o pixels: write these pixels to the pixel cache.
1433 MagickPrivate MagickOffsetType WriteDistributePixelCachePixels(
1434 DistributeCacheInfo *server_info,const RectangleInfo *region,
1435 const MagickSizeType length,const unsigned char *restrict pixels)
1440 register unsigned char
1444 message[MaxTextExtent];
1447 Write distributed pixel cache pixels.
1449 assert(server_info != (DistributeCacheInfo *) NULL);
1450 assert(server_info->signature == MagickSignature);
1451 assert(region != (RectangleInfo *) NULL);
1452 assert(pixels != (const unsigned char *) NULL);
1453 if (length > (MagickSizeType) SSIZE_MAX)
1457 (void) memcpy(p,&server_info->session_key,sizeof(server_info->session_key));
1458 p+=sizeof(server_info->session_key);
1459 (void) memcpy(p,®ion->width,sizeof(region->width));
1460 p+=sizeof(region->width);
1461 (void) memcpy(p,®ion->height,sizeof(region->height));
1462 p+=sizeof(region->height);
1463 (void) memcpy(p,®ion->x,sizeof(region->x));
1464 p+=sizeof(region->x);
1465 (void) memcpy(p,®ion->y,sizeof(region->y));
1466 p+=sizeof(region->y);
1467 (void) memcpy(p,&length,sizeof(length));
1469 count=dpc_send(server_info->file,p-message,message);
1470 if (count != (MagickOffsetType) (p-message))
1472 return(dpc_send(server_info->file,length,pixels));