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_FWRITE:
160 int64_t pointer = READ_INT64((unsigned char*)buffer);
161 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
162 int size = READ_INT32((unsigned char*)buffer + 8);
163 int num = READ_INT32((unsigned char*)buffer + 12);
164 unsigned char datagram[4];
168 server->reallocate_buffer(size * num);
169 server->read_socket((char*)server->buffer, size * num, RENDERFARM_TIMEOUT);
170 bytes = fwrite(server->buffer, size, num, file);
172 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
175 printf("RenderFarmFSServer::handle_request file=%p size=%d num=%d bytes=%d\n",
176 file, size, num, bytes);
180 case RENDERFARM_FSEEK:
182 int64_t pointer = READ_INT64((unsigned char*)buffer);
183 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
184 int64_t offset = READ_INT64((unsigned char*)buffer + 8);
185 int whence = READ_INT32((unsigned char*)buffer + 16);
187 unsigned char datagram[4];
190 return_value = fseeko64(file, offset, whence);
191 STORE_INT32(return_value);
192 server->write_socket((char*)datagram, 4, RENDERFARM_TIMEOUT);
195 printf("RenderFarmFSServer::handle_request file=%p offset=%lld whence=%d result=%d\n",
196 file, offset, whence, result);
200 case RENDERFARM_FTELL:
202 int64_t pointer = READ_INT64((unsigned char*)buffer);
203 FILE *file = (FILE*)Units::int64_to_ptr(pointer);
204 unsigned char datagram[8];
206 int64_t return_value = ftello64(file);
207 STORE_INT64(return_value);
208 server->write_socket((char*)datagram, 8, RENDERFARM_TIMEOUT);
211 printf("RenderFarmFSServer::handle_request file=%p result=%lld\n",
216 case RENDERFARM_STAT:
218 struct stat stat_buf;
219 int return_value = stat(buffer, &stat_buf);
220 server->write_socket((char*)&stat_buf, sizeof(struct stat), RENDERFARM_TIMEOUT);
223 printf("RenderFarmFSServer::handle_request path=%s result=%d\n",
224 buffer, return_value);
228 case RENDERFARM_STAT64:
230 struct stat64 stat_buf;
231 int return_value = stat64(buffer, &stat_buf);
232 server->write_socket((char*)&stat_buf, sizeof(struct stat64), RENDERFARM_TIMEOUT);
235 printf("RenderFarmFSServer::handle_request path=%s result=%d\n",
236 buffer, return_value);