1 #include "renderfarm.h"
2 #include "renderfarmfsserver.h"
11 RenderFarmFSServer::RenderFarmFSServer(RenderFarmServerThread *server)
13 this->server = server;
18 RenderFarmFSServer::~RenderFarmFSServer()
22 void RenderFarmFSServer::initialize()
26 int RenderFarmFSServer::handle_request(int request_id, int request_size, char *buffer)
31 printf("RenderFarmFSServer::handle_request request_id=%d\n", request_id);
34 case RENDERFARM_FOPEN:
39 unsigned char datagram[8];
45 mode = buffer + strlen(path) + 1;
48 file = fopen64(path, mode);
49 file_int64 = Units::ptr_to_int64(file);
50 STORE_INT64(file_int64);
51 server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
53 printf("RenderFarmFSServer::handle_request file=%p path=%s mode=%s\n",
59 case RENDERFARM_FCLOSE:
61 int64_t pointer = READ_INT64((unsigned char*)buffer);
62 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
64 printf("RenderFarmFSServer::handle_request file=%p\n", file);
70 case RENDERFARM_REMOVE:
74 printf("RenderFarmFSServer::handle_request path=%s\n", buffer);
79 case RENDERFARM_RENAME:
81 char *oldpath = buffer;
82 char *newpath = buffer + strlen(oldpath) + 1;
83 rename(oldpath, newpath);
85 printf("RenderFarmFSServer::handle_request old=%s new=%s\n", oldpath, newpath);
90 case RENDERFARM_FGETC:
92 int64_t pointer = READ_INT64((unsigned char*)buffer);
93 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
94 unsigned char datagram[1];
95 datagram[0] = fgetc(file);
96 server->write_socket((char*)datagram, 1, RENDERFARM_TIMEOUT);
98 printf("RenderFarmFSServer::handle_request file=%p\n", file);
103 case RENDERFARM_FPUTC:
105 int64_t pointer = READ_INT64((unsigned char*)buffer);
106 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
107 fputc(buffer[8], file);
110 printf("RenderFarmFSServer::handle_request file=%p\n", file);
114 case RENDERFARM_FREAD:
116 int64_t pointer = READ_INT64((unsigned char*)buffer);
117 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
118 int size = READ_INT32((unsigned char*)buffer + 8);
119 int num = READ_INT32((unsigned char*)buffer + 12);
120 unsigned char datagram[4];
124 server->reallocate_buffer(size * num);
125 bytes = fread(server->buffer, size, num, file);
127 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
128 server->write_socket((char*)server->buffer, size * bytes, RENDERFARM_TIMEOUT);
131 printf("RenderFarmFSServer::handle_request file=%p size=%d num=%d bytes=%d\n",
132 file, size, num, bytes);
136 case RENDERFARM_FGETS:
138 int64_t pointer = READ_INT64((unsigned char*)buffer);
139 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
140 int size = READ_INT32((unsigned char*)buffer + 8);
141 unsigned char datagram[4];
144 server->reallocate_buffer(size);
145 char *return_value = fgets((char*)server->buffer, size, file);
149 bytes = strlen(return_value) + 1;
152 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
153 server->write_socket((char*)server->buffer, bytes, RENDERFARM_TIMEOUT);
158 case RENDERFARM_FILENO:
160 int64_t pointer = READ_INT64((unsigned char*)buffer);
161 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
162 unsigned char datagram[4];
165 int return_value = fileno(file);
166 STORE_INT32(return_value);
167 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
169 printf("RenderFarmFSServer::handle_request file=%p fileno=%d\n",
175 case RENDERFARM_FWRITE:
177 int64_t pointer = READ_INT64((unsigned char*)buffer);
178 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
179 int size = READ_INT32((unsigned char*)buffer + 8);
180 int num = READ_INT32((unsigned char*)buffer + 12);
181 unsigned char datagram[4];
185 server->reallocate_buffer(size * num);
186 server->read_socket((char*)server->buffer, size * num, RENDERFARM_TIMEOUT);
187 bytes = fwrite(server->buffer, size, num, file);
189 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
192 printf("RenderFarmFSServer::handle_request file=%p size=%d num=%d bytes=%d\n",
193 file, size, num, bytes);
197 case RENDERFARM_FSEEK:
199 int64_t pointer = READ_INT64((unsigned char*)buffer);
200 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
201 int64_t offset = READ_INT64((unsigned char*)buffer + 8);
202 int whence = READ_INT32((unsigned char*)buffer + 16);
204 unsigned char datagram[4];
207 return_value = fseeko64(file, offset, whence);
208 STORE_INT32(return_value);
209 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
212 printf("RenderFarmFSServer::handle_request file=%p offset=%lld whence=%d result=%d\n",
213 file, offset, whence, result);
217 case RENDERFARM_FTELL:
219 int64_t pointer = READ_INT64((unsigned char*)buffer);
220 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
221 unsigned char datagram[8];
223 int64_t return_value = ftello64(file);
224 STORE_INT64(return_value);
225 server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
228 printf("RenderFarmFSServer::handle_request file=%p result=%lld\n",
233 case RENDERFARM_STAT:
235 struct stat stat_buf;
236 int return_value = stat(buffer, &stat_buf);
237 server->write_socket((char*)&stat_buf, sizeof(struct stat), RENDERFARM_TIMEOUT);
240 printf("RenderFarmFSServer::handle_request path=%s result=%d\n",
241 buffer, return_value);
245 case RENDERFARM_STAT64:
247 struct stat64 stat_buf;
248 int return_value = stat64(buffer, &stat_buf);
249 server->write_socket((char*)&stat_buf, sizeof(struct stat64), RENDERFARM_TIMEOUT);
252 printf("RenderFarmFSServer::handle_request path=%s result=%d\n",
253 buffer, return_value);