static int SendValue(NETFILE *fp, ValueStruct *value) { int ret = 0; size_t size; if (value == NULL) { SendLength(fp, 0); } else { size = ValueByteLength(value); SendLength(fp, size); ret = Send(fp, ValueByte(value), size); } return ret; }
extern MonObjectType RequestImportBLOB( NETFILE *fp, char *fname) { MonObjectType obj; char buff[SIZE_BUFF]; FILE *fpf; struct stat sb; size_t size , left; ENTER_FUNC; obj = GL_OBJ_NULL; RequestBLOB(fp,BLOB_IMPORT); ON_IO_ERROR(fp,badio); if ( RecvPacketClass(fp) == BLOB_OK ) { obj = RecvObject(fp); ON_IO_ERROR(fp,badio); if ( ( fpf = fopen(fname,"r") ) != NULL ) { fstat(fileno(fpf),&sb); left = sb.st_size; SendLength(fp,left); Flush(fp); while ( left > 0 ) { size = ( left > SIZE_BUFF ) ? SIZE_BUFF : left; fread(buff,size,1,fpf); Send(fp,buff,size); ON_IO_ERROR(fp,badio); Flush(fp); left -= size; } fclose(fpf); } else { dbgprintf("could not open for read: %s", fname); SendLength(fp,0); Flush(fp); } } badio: LEAVE_FUNC; return (obj); }
extern void SendString(NETFILE *fp, char *str) { size_t size; if (str != NULL) { size = strlen(str); } else { size = 0; } SendLength(fp, size); if (size > 0) { Send(fp, str, size); } }
extern size_t RequestWriteBLOB( NETFILE *fp, MonObjectType obj, unsigned char *buff, size_t size) { size_t wrote; ENTER_FUNC; wrote = 0; RequestBLOB(fp,BLOB_WRITE); ON_IO_ERROR(fp,badio); SendObject(fp,obj); ON_IO_ERROR(fp,badio); if ( RecvPacketClass(fp) == BLOB_OK ) { SendLength(fp,size); ON_IO_ERROR(fp,badio); if ( size > 0 ) { Send(fp,buff,size); ON_IO_ERROR(fp,badio); wrote = RecvLength(fp); ON_IO_ERROR(fp,badio); } } badio: LEAVE_FUNC; return (wrote); }
extern void SendLBS(NETFILE *fp, LargeByteString *lbs) { SendLength(fp, LBS_Size(lbs)); if (LBS_Size(lbs) > 0) { Send(fp, LBS_Body(lbs), LBS_Size(lbs)); } }