mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 04:33:04 -04:00
added send-by-file
This commit is contained in:
parent
5528735c9b
commit
8242b1c4b7
@ -45,11 +45,23 @@ class DistributedLargeBlobSender(DistributedObject.DistributedObject):
|
|||||||
self.privOnBlobComplete()
|
self.privOnBlobComplete()
|
||||||
|
|
||||||
def setFilename(self, filename):
|
def setFilename(self, filename):
|
||||||
DistributedLargeBlobSender.notify.debug('setFilename')
|
DistributedLargeBlobSender.notify.debug('setFilename: %s' % filename)
|
||||||
assert self.useDisk
|
assert self.useDisk
|
||||||
self.blob = ''
|
|
||||||
|
import os
|
||||||
|
origDir = os.getcwd()
|
||||||
|
bPath = LargeBlobSenderConsts.getLargeBlobPath()
|
||||||
|
try:
|
||||||
|
os.chdir(bPath)
|
||||||
|
except OSError:
|
||||||
DistributedLargeBlobSender.notify.error(
|
DistributedLargeBlobSender.notify.error(
|
||||||
'large blob transfer by file not yet implemented')
|
'could not access %s' % bPath)
|
||||||
|
f = file(filename, 'rb')
|
||||||
|
self.blob = f.read()
|
||||||
|
f.close()
|
||||||
|
os.unlink(filename)
|
||||||
|
os.chdir(origDir)
|
||||||
|
|
||||||
self.privOnBlobComplete()
|
self.privOnBlobComplete()
|
||||||
|
|
||||||
def isComplete(self):
|
def isComplete(self):
|
||||||
|
@ -20,11 +20,35 @@ class DistributedLargeBlobSenderAI(DistributedObjectAI.DistributedObjectAI):
|
|||||||
self.generateWithRequired(zoneId)
|
self.generateWithRequired(zoneId)
|
||||||
|
|
||||||
# send the data
|
# send the data
|
||||||
if useDisk:
|
|
||||||
DistributedLargeBlobSenderAI.notify.error(
|
|
||||||
'large blob transfer by file not yet implemented')
|
|
||||||
else:
|
|
||||||
s = str(data)
|
s = str(data)
|
||||||
|
if useDisk:
|
||||||
|
# write the data to a file and tell the client where to get it
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
origDir = os.getcwd()
|
||||||
|
bPath = LargeBlobSenderConsts.getLargeBlobPath()
|
||||||
|
try:
|
||||||
|
os.chdir(bPath)
|
||||||
|
except OSError:
|
||||||
|
DistributedLargeBlobSenderAI.notify.error(
|
||||||
|
'could not access %s' % bPath)
|
||||||
|
# find an unused temp filename
|
||||||
|
while 1:
|
||||||
|
num = random.randrange((1 << 30)-1)
|
||||||
|
filename = LargeBlobSenderConsts.FilePattern % num
|
||||||
|
try:
|
||||||
|
os.stat(filename)
|
||||||
|
except OSError:
|
||||||
|
break
|
||||||
|
# NOTE: there's a small chance of a race condition here, if
|
||||||
|
# the file is created by another AI just after the stat fails
|
||||||
|
f = file(filename, 'wb')
|
||||||
|
f.write(s)
|
||||||
|
f.close()
|
||||||
|
os.chdir(origDir)
|
||||||
|
self.sendUpdateToAvatarId(self.targetAvId,
|
||||||
|
'setFilename', [filename])
|
||||||
|
else:
|
||||||
chunkSize = LargeBlobSenderConsts.ChunkSize
|
chunkSize = LargeBlobSenderConsts.ChunkSize
|
||||||
while len(s):
|
while len(s):
|
||||||
self.sendUpdateToAvatarId(self.targetAvId,
|
self.sendUpdateToAvatarId(self.targetAvId,
|
||||||
|
@ -3,3 +3,13 @@
|
|||||||
USE_DISK = 0x01
|
USE_DISK = 0x01
|
||||||
|
|
||||||
ChunkSize = 100
|
ChunkSize = 100
|
||||||
|
|
||||||
|
FilePattern = 'largeBlob.%s'
|
||||||
|
|
||||||
|
def getLargeBlobPath():
|
||||||
|
path = config.GetString('large-blob-path', '')
|
||||||
|
if len(path) == 0:
|
||||||
|
assert 0, (
|
||||||
|
'you must config large-blob-path to beta/largeblob, i.e.\n'
|
||||||
|
'large-blob-path i:\\beta\\largeblob')
|
||||||
|
return path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user