r668: Configure.in and autogen.sh cleanup based on ideas by giskard.
[cinelerra_cv.git] / cinelerra / renderfarmfsclient.C
blob548cf37c1a974d601e2ba37703ef105f21f4801b
1 // Disable 64 bit indirections so we can override both functions.
2 #undef _LARGEFILE64_SOURCE
3 #undef _LARGEFILE_SOURCE
4 #undef _FILE_OFFSET_BITS
6 #include "mutex.h"
7 #include "renderfarm.h"
8 #include "renderfarmclient.h"
9 #include "renderfarmfsclient.h"
10 #include "renderfarmfsserver.inc"
11 #include "units.h"
13 #include <dlfcn.h>
14 #include <fcntl.h>
15 #include <stdarg.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
22 #define DEBUG 0
24 // These are hacks to get all the file I/O libraries to transparently 
25 // go over the network without rewriting them.
28 extern "C"
37 RenderFarmFSClient *renderfarm_fs_global = 0;
40 // open doesn't seem overridable
41 // int open (__const char *path, int flags, ...)
42 // {
43 //      static int (*func)(__const char *__file, int __oflag) = 0;
44 //      int result = -1;
45 // printf("open %s\n", path);
46 // 
47 //      if (!func)
48 //      func = (int(*)(const char *path, int flags))dlsym(RTLD_NEXT, "open");
49 //      
50 //      result = (*func)(path, flags);
51 //      return result;
52 // }
55 FILE* fopen(const char *path, const char *mode)
57         static FILE* (*func)(const char *path, const char *mode) = 0;
58 // This pointer is meaningless except on the server.
59         FILE *result = 0;
61         if (!func)
62         func = (FILE*(*)(const char *path, const char *mode))dlsym(RTLD_NEXT, "fopen");
64 // VFS path
65         if(!strncmp(path, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
66         {
67                 renderfarm_fs_global->lock();
68                 result = renderfarm_fs_global->fopen(path, mode);
69                 renderfarm_fs_global->unlock();
70         }
71         else
72                 result = (*func)(path, mode);
74     return result;
77 FILE* fopen64(const char *path, const char *mode)
79         static FILE* (*func)(const char *path, const char *mode) = 0;
80 // This pointer is meaningless except on the server.
81         FILE *result = 0;
83 //printf("fopen64 %s\n", path);
84         if (!func)
85         func = (FILE*(*)(const char *path, const char *mode))dlsym(RTLD_NEXT, "fopen64");
87 // VFS path
88         if(!strncmp(path, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
89         {
90                 renderfarm_fs_global->lock();
91                 result = renderfarm_fs_global->fopen(path, mode);
92                 renderfarm_fs_global->unlock();
93         }
94         else
95                 result = (*func)(path, mode);
97     return result;
102 int fclose(FILE *file)
104         static int (*func)(FILE *) = 0;
105         int result = 0, done = 0;
106         if(!func)
107         func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fclose");
108 //printf("fclose\n");
110         if(renderfarm_fs_global)
111         {
112                 renderfarm_fs_global->lock();
113                 if(renderfarm_fs_global->is_open(file))
114                 {
115                         result = renderfarm_fs_global->fclose(file);
116                         done = 1;
117                 }
118                 renderfarm_fs_global->unlock();
119         }
121         if(!done) result = (*func)(file);
122         return result;
125 int fileno (FILE *stream)
127         static int (*func)(FILE *) = 0;
128         int result = -1;
129         if(!func)
130         func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fileno");
131         if(renderfarm_fs_global)
132         {
133                 renderfarm_fs_global->lock();
134                 if(renderfarm_fs_global->is_open(stream))
135                 {
136                         result = renderfarm_fs_global->fileno(stream);
137                 }
138                 renderfarm_fs_global->unlock();
139         }
140         else
141                 result = (*func)(stream);
142         return result;
145 // int fflush(FILE *file)
146 // {
147 //      static int (*func)(FILE *) = 0;
148 //      int result = 0, done = 0;
149 //      if(!func)
150 //      func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fflush");
151 // //printf("fflush\n");
152 // 
153 //      renderfarm_fs_global->lock();
154 //      if(renderfarm_fs_global->is_open(file))
155 //      {
156 //              result = renderfarm_fs_global->fflush(file);
157 //              done = 1;
158 //      }
159 //      renderfarm_fs_global->unlock();
160 //      
161 //      if(!done) result = (*func)(file);
162 //      return result;
163 // }
165 int remove (__const char *__filename)
167         static int (*func)(__const char *) = 0;
168         int result = 0;
169         if(!func)
170         func = (int(*)(__const char *))dlsym(RTLD_NEXT, "remove");
171 //printf("remove\n");
173 // VFS path
174         if(!strncmp(__filename, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
175         {
176                 renderfarm_fs_global->lock();
177                 result = renderfarm_fs_global->remove(__filename);
178                 renderfarm_fs_global->unlock();
179         }
180         else
181                 result = (*func)(__filename);
183         return result;
186 int rename (__const char *__old, __const char *__new)
188         static int (*func)(__const char *, __const char *) = 0;
189         int result = 0;
190         if(!func)
191         func = (int(*)(__const char *, __const char *))dlsym(RTLD_NEXT, "rename");
192 //printf("rename\n");
194 // VFS path
195         if(!strncmp(__old, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
196         {
197                 renderfarm_fs_global->lock();
198                 result = renderfarm_fs_global->rename(__old, __new);
199                 renderfarm_fs_global->unlock();
200         }
201         else
202                 result = (*func)(__old, __new);
204         return result;
207 int fgetc (FILE *__stream)
209         static int (*func)(FILE *) = 0;
210         int result = 0, done = 0;
211         if(!func)
212         func = (int(*)(FILE *))dlsym(RTLD_NEXT, "fgetc");
213 //printf("fgetc\n");
215         if(renderfarm_fs_global)
216         {
217                 renderfarm_fs_global->lock();
218                 if(renderfarm_fs_global->is_open(__stream))
219                 {
220                         result = renderfarm_fs_global->fgetc(__stream);
221                         done = 1;
222                 }
223                 renderfarm_fs_global->unlock();
224         }
226         if(!done) result = (*func)(__stream);
227         return result;
230 int getc (FILE *__stream)
232         return fgetc(__stream);
235 int fputc (int __c, FILE *__stream)
237         static int (*func)(int, FILE *) = 0;
238         int result = 0, done = 0;
239         if(!func)
240         func = (int(*)(int, FILE *))dlsym(RTLD_NEXT, "fputc");
241 //printf("fputc\n");
243         if(renderfarm_fs_global)
244         {
245                 renderfarm_fs_global->lock();
246                 if(renderfarm_fs_global->is_open(__stream))
247                 {
248                         result = renderfarm_fs_global->fputc(__c, __stream);
249                         done = 1;
250                 }
251                 renderfarm_fs_global->unlock();
252         }
254         if(!done) result = (*func)(__c, __stream);
255         return result;
258 int putc (int __c, FILE *__stream)
260         return fputc(__c, __stream);
263 size_t fread (void *__restrict __ptr, size_t __size,
264                      size_t __n, FILE *__restrict __stream)
266         static int (*func)(void *, size_t, size_t, FILE *) = 0;
267         size_t result = 0;
268         int done = 0;
269         if(!func)
270         func = (int(*)(void *, size_t, size_t, FILE *))dlsym(RTLD_NEXT, "fread");
271 //printf("fread\n");
273         if(renderfarm_fs_global)
274         {
275                 renderfarm_fs_global->lock();
276                 if(renderfarm_fs_global->is_open(__stream))
277                 {
278                         result = renderfarm_fs_global->fread(__ptr, __size, __n, __stream);
279                         done = 1;
280                 }
281                 renderfarm_fs_global->unlock();
282         }
284         if(!done) result = (*func)(__ptr, __size, __n, __stream);
286         return result;
289 size_t fwrite (__const void *__restrict __ptr, size_t __size,
290                       size_t __n, FILE *__restrict __s)
292         static int (*func)(__const void *, size_t, size_t, FILE *) = 0;
293         size_t result = 0;
294         int done = 0;
295         if(!func)
296         func = (int(*)(__const void *, size_t, size_t, FILE *))dlsym(RTLD_NEXT, "fwrite");
297 //printf("fwrite\n");
299         if(renderfarm_fs_global)
300         {
301                 renderfarm_fs_global->lock();
302                 if(renderfarm_fs_global->is_open(__s))
303                 {
304                         result = renderfarm_fs_global->fwrite(__ptr, __size, __n, __s);
305                         done = 1;
306                 }
307                 renderfarm_fs_global->unlock();
308         }
310         if(!done) result = (*func)(__ptr, __size, __n, __s);
312         return result;
315 int fseek (FILE *__stream, long int __off, int __whence)
317         static int (*func)(FILE *, long int, int) = 0;
318         int result = 0;
319         int done = 0;
320         if(!func)
321         func = (int(*)(FILE *, long int, int))dlsym(RTLD_NEXT, "fseek");
322 //printf("fseek\n");
324         if(renderfarm_fs_global)
325         {
326                 renderfarm_fs_global->lock();
327                 if(renderfarm_fs_global->is_open(__stream))
328                 {
329                         result = renderfarm_fs_global->fseek(__stream, __off, __whence);
330                         done = 1;
331                 }
332                 renderfarm_fs_global->unlock();
333         }
335         if(!done) result = (*func)(__stream, __off, __whence);
337         return result;
340 int fseeko64 (FILE *__stream, __off64_t __off, int __whence)
342         static int (*func)(FILE *, __off64_t, int) = 0;
343         int result = 0;
344         int done = 0;
345         if(!func)
346         func = (int(*)(FILE *, __off64_t, int))dlsym(RTLD_NEXT, "fseeko64");
347 //printf("fseeko64\n");
349         if(renderfarm_fs_global)
350         {
351                 renderfarm_fs_global->lock();
352                 if(renderfarm_fs_global->is_open(__stream))
353                 {
354                         result = renderfarm_fs_global->fseek(__stream, __off, __whence);
355                         done = 1;
356                 }
357                 renderfarm_fs_global->unlock();
358         }
360         if(!done) result = (*func)(__stream, __off, __whence);
362         return result;
365 long int ftell (FILE *__stream)
367         static long int (*func)(FILE *) = 0;
368         int result = 0;
369         int done = 0;
370         if(!func)
371         func = (long int(*)(FILE *))dlsym(RTLD_NEXT, "ftell");
372 //printf("ftell\n");
374         if(renderfarm_fs_global)
375         {
376                 renderfarm_fs_global->lock();
377                 if(renderfarm_fs_global->is_open(__stream))
378                 {
379                         result = renderfarm_fs_global->ftell(__stream);
380                         done = 1;
381                 }
382                 renderfarm_fs_global->unlock();
383         }
385         if(!done) result = (*func)(__stream);
387         return result;
390 __off64_t ftello64 (FILE *__stream)
392         static __off64_t (*func)(FILE *) = 0;
393         __off64_t result = 0;
394         int done = 0;
395         if(!func)
396         func = (__off64_t(*)(FILE *))dlsym(RTLD_NEXT, "ftello64");
398         if(renderfarm_fs_global)
399         {
400                 renderfarm_fs_global->lock();
401                 if(renderfarm_fs_global->is_open(__stream))
402                 {
403                         result = renderfarm_fs_global->ftell(__stream);
404                         done = 1;
405                 }
406                 renderfarm_fs_global->unlock();
407         }
409         if(!done) result = (*func)(__stream);
411         return result;
412         return (*func)(__stream);
416 // Glibc inlines the stat functions and redirects them to __xstat functions
417 int __xstat (int __ver, __const char *__filename,
418                     struct stat *__stat_buf)
420         static int (*func)(int __ver, __const char *__filename,
421                     struct stat *__stat_buf) = 0;
423 // This pointer is meaningless except on the server.
424         int result = 0;
426         if (!func)
427         func = (int(*)(int __ver, __const char *__filename,
428                     struct stat *__stat_buf))dlsym(RTLD_NEXT, "__xstat");
430 // VFS path
431         if(!strncmp(__filename, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
432         {
433                 renderfarm_fs_global->lock();
434                 result = renderfarm_fs_global->stat(__filename, __stat_buf);
435                 renderfarm_fs_global->unlock();
436         }
437         else
438         {
439                 result = (*func)(__ver, __filename, __stat_buf);
440         }
442     return result;
445 int __xstat64 (int __ver, __const char *__filename,
446                       struct stat64 *__stat_buf)
448         static int (*func)(int __ver, __const char *__restrict __file,
449                  struct stat64 *__restrict __buf) = 0;
450 // This pointer is meaningless except on the server.
451         int result = 0;
453         if (!func)
454         func = (int(*)(int __ver, __const char *__restrict __file,
455                                         struct stat64 *__restrict __buf))dlsym(RTLD_NEXT, "__xstat64");
457 // VFS path
458         if(!strncmp(__filename, RENDERFARM_FS_PREFIX, strlen(RENDERFARM_FS_PREFIX)))
459         {
460                 renderfarm_fs_global->lock();
461                 result = renderfarm_fs_global->stat64(__filename, __stat_buf);
462                 renderfarm_fs_global->unlock();
463         }
464         else
465                 result = (*func)(__ver, __filename, __stat_buf);
467     return result;
470 char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
472         static char* (*func)(char *__restrict __s, int __n, FILE *__restrict __stream) = 0;
473         char *result = 0;
474         int done = 0;
475         if(!func)
476         func = (char*(*)(char *__restrict __s, int __n, FILE *__restrict __stream))dlsym(RTLD_NEXT, "fgets");
478         if(renderfarm_fs_global)
479         {
480                 renderfarm_fs_global->lock();
481                 if(renderfarm_fs_global->is_open(__stream))
482                 {
483                         result = renderfarm_fs_global->fgets(__s, __n, __stream);
484                         done = 1;
485                 }
486                 renderfarm_fs_global->unlock();
487         }
489         if(!done) result = (*func)(__s, __n, __stream);
491         return result;
518 RenderFarmFSClient::RenderFarmFSClient(RenderFarmClientThread *client)
520         mutex_lock = new Mutex;
521         this->client = client;
524 RenderFarmFSClient::~RenderFarmFSClient()
526         delete mutex_lock;
527 // Must not access filesystem until we get here
528         renderfarm_fs_global = 0;
531 void RenderFarmFSClient::initialize()
533         renderfarm_fs_global = this;
536 void RenderFarmFSClient::lock()
538         mutex_lock->lock();
541 void RenderFarmFSClient::unlock()
543         mutex_lock->unlock();
546 int RenderFarmFSClient::is_open(FILE *ptr)
548         for(int i = 0; i < files.total; i++)
549                 if(files.values[i] == ptr) return 1;
550         return 0;
553 void RenderFarmFSClient::set_open(FILE *ptr)
555         files.append(ptr);
558 void RenderFarmFSClient::unset_open(FILE *ptr)
560         files.remove(ptr);
564 FILE* RenderFarmFSClient::fopen(const char *path, const char *mode)
566         int len = strlen(path) - strlen(RENDERFARM_FS_PREFIX) + strlen(mode) + 2;
567         char *buffer = new char[len];
568         FILE *file = 0;
569         strcpy(buffer, path + strlen(RENDERFARM_FS_PREFIX));
570         strcpy(buffer + strlen(buffer) + 1, mode);
573         client->lock();
574         if(!client->send_request_header(RENDERFARM_FOPEN, 
575                 len))
576         {
577                 if(client->write_socket(buffer, len, RENDERFARM_TIMEOUT) == len)
578                 {
579                         unsigned char data[8];
580                         if(client->read_socket((char*)data, 8, RENDERFARM_TIMEOUT) == 8)
581                         {
582                                 int64_t file_int64 = READ_INT64(data);
583                                 file = (FILE*)Units::int64_to_ptr(file_int64);
584                         }
585                 }
586         }
587         client->unlock();
588         if(file) set_open(file);
589         delete [] buffer;
591 if(DEBUG)
592 printf("RenderFarmFSClient::fopen path=%s mode=%s file=%p\n", path, mode, file);
594         return file;
597 int RenderFarmFSClient::fclose(FILE *file)
599         int result = 0;
600         unsigned char datagram[8];
601         int i = 0;
602         int file_int64 = Units::ptr_to_int64(file);
603         STORE_INT64(file_int64);
605         client->lock();
606         if(!client->send_request_header(RENDERFARM_FCLOSE, 8))
607         {
608                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) == 8)
609                         result = 0;
610                 else
611                         result = -1;
612         }
613         else
614                 result = -1;
615         client->unlock();
616         unset_open(file);
617 if(DEBUG)
618 printf("RenderFarmFSClient::fclose file=%p\n", file);
619         return result;
622 int RenderFarmFSClient::fileno(FILE *file)
624         int result = 0;
625         unsigned char datagram[8];
626         int i = 0;
627         int file_int64 = Units::ptr_to_int64(file);
628         STORE_INT64(file_int64);
630         client->lock();
631         if(!client->send_request_header(RENDERFARM_FILENO, 8))
632         {
633                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) == 8)
634                 {
635                         unsigned char data[4];
636                         if(client->read_socket((char*)data, 4, RENDERFARM_TIMEOUT) == 4)
637                         {
638                                 result = READ_INT32(data);
639                         }
640                 }
641                 else
642                         result = -1;
643         }
644         else
645                 result = -1;
646         client->unlock();
647 if(DEBUG)
648 printf("RenderFarmFSClient::fileno file=%p result=%d\n", file, result);
649         return result;
652 int RenderFarmFSClient::remove (__const char *__filename)
654         int result = 0;
655         int len = strlen(__filename) + 1;
656         char *datagram = new char[len];
657         strcpy(datagram, __filename);
658         
659         client->lock();
660         if(!client->send_request_header(RENDERFARM_REMOVE, len))
661         {
662                 if(client->write_socket(datagram, len, RENDERFARM_TIMEOUT) != len)
663                         result = -1;
664                 else
665                         result = 0;
666         }
667         else
668                 result = -1;
669         client->unlock();
671         delete [] datagram;
672 if(DEBUG)
673 printf("RenderFarmFSClient::remove path=%s\n", __filename);
674         return result;
677 int RenderFarmFSClient::rename (__const char *__old, __const char *__new)
679         int result = 0;
680         int len = strlen(__old) + 1 + strlen(__new) + 1;
681         char *datagram = new char[len];
682         strcpy(datagram, __old);
683         strcpy(datagram + strlen(__old) + 1, __new);
684         
685         client->lock();
686         if(!client->send_request_header(RENDERFARM_RENAME, len))
687         {
688                 if(client->write_socket(datagram, len, RENDERFARM_TIMEOUT) != len)
689                         result = -1;
690                 else
691                         result = 0;
692         }
693         else
694                 result = -1;
695         client->unlock();
697         delete [] datagram;
698 if(DEBUG)
699 printf("RenderFarmFSClient::remove old=%s new=%s\n", __old, __new);
700         return result;
703 int RenderFarmFSClient::fgetc (FILE *__stream)
705         int result = 0;
706         unsigned char datagram[8];
707         int i = 0;
708         int file_int64 = Units::ptr_to_int64(__stream);
709         STORE_INT64(file_int64);
710         
711         client->lock();
712         if(!client->send_request_header(RENDERFARM_FGETC, 8))
713         {
714                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) != 8)
715                         result = -1;
716                 else
717                 {
718                         if(client->read_socket((char*)datagram, 1, RENDERFARM_TIMEOUT) != 1)
719                                 result = -1;
720                         else
721                         {
722                                 result = datagram[0];
723                         }
724                 }
725         }
726         else
727                 result = -1;
728         client->unlock();
729 if(DEBUG)
730 printf("RenderFarmFSClient::fgetc file=%p result=%02x\n", __stream, result);
732         return result;
735 int RenderFarmFSClient::fputc (int __c, FILE *__stream)
737         int result = 0;
738         unsigned char datagram[9];
739         int i = 0;
740         int file_int64 = Units::ptr_to_int64(__stream);
741         STORE_INT64(file_int64);
742         datagram[i++] = __c;
743         
744         client->lock();
745         if(!client->send_request_header(RENDERFARM_FPUTC, 9))
746         {
747                 if(client->write_socket((char*)datagram, 9, RENDERFARM_TIMEOUT) != 9)
748                         result = -1;
749                 else
750                         result = __c;
751         }
752         else
753                 result = -1;
754         client->unlock();
755 if(DEBUG)
756 printf("RenderFarmFSClient::fputc file=%p result=%02x\n", __stream, result);
758         return result;
761 char* RenderFarmFSClient::fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
763         char *result = 0;
764         int bytes = 0;
765         unsigned char datagram[12];
766         int i = 0;
767         int file_int64 = Units::ptr_to_int64(__stream);
768         STORE_INT64(file_int64);
769         STORE_INT32(__n);
770         
771         client->lock();
772         if(!client->send_request_header(RENDERFARM_FGETS, 12))
773         {
774                 if(client->write_socket((char*)datagram, 12, RENDERFARM_TIMEOUT) == 12)
775                 {
776 // fgets bytes to follow
777                         if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) == 4)
778                         {
779 // fgets data
780                                 bytes = READ_INT32(datagram);
781                                 if(bytes)
782                                 {
783                                         if(client->read_socket((char*)__s, bytes, RENDERFARM_TIMEOUT) == bytes)
784                                         {
785                                                 result = __s;
786                                         }
787                                 }
788                         }
789                 }
790         }
791         else
792                 result = 0;
793         client->unlock();
794 if(DEBUG)
795 printf("RenderFarmFSClient::fgets file=%p string=%p size=%d bytes=%p\n", 
796 __stream, __s, bytes, bytes);
798         return result;
802 size_t RenderFarmFSClient::fread (void *__restrict __ptr, size_t __size,
803                      size_t __n, FILE *__restrict __stream)
805         size_t result = 0;
806         unsigned char datagram[16];
807         int i = 0;
808         int file_int64 = Units::ptr_to_int64(__stream);
809         STORE_INT64(file_int64);
810         STORE_INT32(__size);
811         STORE_INT32(__n);
812         
813         client->lock();
814         if(!client->send_request_header(RENDERFARM_FREAD, 16))
815         {
816                 if(client->write_socket((char*)datagram, 16, RENDERFARM_TIMEOUT) != 16)
817                         result = 0;
818                 else
819                 {
820 // fread result
821                         if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) != 4)
822                                 result = 0;
823                         else
824                         {
825 // fread data
826                                 result = READ_INT32(datagram);
827                                 if(client->read_socket((char*)__ptr, __size * result, RENDERFARM_TIMEOUT) != 
828                                         __size * result)
829                                         result = 0;
830                         }
831                 }
832         }
833         else
834                 result = 0;
835         client->unlock();
836 if(DEBUG)
837 printf("RenderFarmFSClient::fread file=%p size=%d num=%d result=%d\n", 
838 __stream, __size, __n, result);
840         return result;
843 size_t RenderFarmFSClient::fwrite (__const void *__restrict __ptr, size_t __size,
844                       size_t __n, FILE *__restrict __s)
846         size_t result = 0;
847         unsigned char datagram[16];
848         int i = 0;
849         int file_int64 = Units::ptr_to_int64(__s);
850         STORE_INT64(file_int64);
851         STORE_INT32(__size);
852         STORE_INT32(__n);
853         
854         client->lock();
855         if(!client->send_request_header(RENDERFARM_FWRITE, 16))
856         {
857                 if(client->write_socket((char*)datagram, 16, RENDERFARM_TIMEOUT) != 16)
858                         result = 0;
859                 else
860                 {
861 // fwrite data
862                         if(client->write_socket((char*)__ptr, __size * __n, RENDERFARM_TIMEOUT) != 
863                                 __size * __n)
864                         result = 0;
865                         else
866                         {
867 // fwrite result
868                                 if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) != 4)
869                                         result = 0;
870                                 else
871                                 {
872                                         result = READ_INT32(datagram);
873                                 }
874                         }
875                 }
876         }
877         else
878                 result = 0;
879         client->unlock();
880 if(DEBUG)
881 printf("RenderFarmFSClient::fwrite file=%p size=%d num=%d result=%d\n", 
882 __s, __size, __n, result);
884         return result;
887 int RenderFarmFSClient::fseek (FILE *__stream, int64_t __off, int __whence)
889         int result = 0;
890         unsigned char datagram[20];
891         int i = 0;
892         int file_int64 = Units::ptr_to_int64(__stream);
893         STORE_INT64(file_int64);
894         STORE_INT64(__off);
895         STORE_INT32(__whence);
897         client->lock();
898         if(!client->send_request_header(RENDERFARM_FSEEK, 20))
899         {
900                 if(client->write_socket((char*)datagram, 20, RENDERFARM_TIMEOUT) != 20)
901                         result = -1;
902                 else
903                 {
904                         if(client->read_socket((char*)datagram, 4, RENDERFARM_TIMEOUT) != 4)
905                                 result = -1;
906                         else
907                                 result = READ_INT32(datagram);
908                 }
909         }
910         else
911                 result = -1;
912         client->unlock();
913 if(DEBUG)
914 printf("RenderFarmFSClient::fseek stream=%p offset=%lld whence=%d result=%d\n", 
915 __stream, __off, __whence, result);
916         return result;
919 int64_t RenderFarmFSClient::ftell (FILE *__stream)
921         int64_t result = 0;
922         unsigned char datagram[8];
923         int i = 0;
924         int file_int64 = Units::ptr_to_int64(__stream);
925         STORE_INT64(file_int64);
927         client->lock();
928         if(!client->send_request_header(RENDERFARM_FTELL, 8))
929         {
930                 if(client->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) != 8)
931                         result = -1;
932                 else
933                 {
934                         if(client->read_socket((char*)datagram, 8, RENDERFARM_TIMEOUT) != 8)
935                                 result = -1;
936                         else
937                                 result = READ_INT64(datagram);
938                 }
939         }
940         else
941                 result = -1;
942         client->unlock();
943 if(DEBUG)
944 printf("RenderFarmFSClient::fseek stream=%p result=%lld\n", 
945 __stream, result);
946         return result;
949 int RenderFarmFSClient::stat (__const char *__restrict __file,
950                  struct stat *__restrict __buf)
952         int len = strlen(__file) + 1;
953         int result = 0;
955         client->lock();
956         if(!client->send_request_header(RENDERFARM_STAT, len))
957         {
958                 if(client->write_socket((char*)__file + strlen(RENDERFARM_FS_PREFIX), len, RENDERFARM_TIMEOUT) == len)
959                 {
960                         if(client->read_socket((char*)__buf, sizeof(struct stat), RENDERFARM_TIMEOUT) == sizeof(struct stat))
961                         {
962                                 ;
963                         }
964                         else
965                                 result = 1;
966                 }
967                 else
968                         result = 1;
969         }
970         else
971                 result = 1;
972         client->unlock();
973 if(DEBUG)
974 printf("RenderFarmFSClient::stat path=%s\n", __file);
976         return result;
981 int RenderFarmFSClient::stat64 (__const char *__restrict __file,
982                    struct stat64 *__restrict __buf)
984         int len = strlen(__file) + 1;
985         int result = 0;
987         client->lock();
988         if(!client->send_request_header(RENDERFARM_STAT64, len))
989         {
990                 if(client->write_socket((char*)__file + strlen(RENDERFARM_FS_PREFIX), len, RENDERFARM_TIMEOUT) == len)
991                 {
992                         if(client->read_socket((char*)__buf, sizeof(struct stat64), RENDERFARM_TIMEOUT) == sizeof(struct stat64))
993                         {
994                                 ;
995                         }
996                         else
997                                 result = 1;
998                 }
999                 else
1000                         result = 1;
1001         }
1002         else
1003                 result = 1;
1004         client->unlock();
1005 if(DEBUG)
1006 printf("RenderFarmFSClient::stat64 path=%s\n", __file);
1008         return result;