Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > interrupt the file sending if the file size over the quota...someerrors here...

Reply
Thread Tools

interrupt the file sending if the file size over the quota...someerrors here...

 
 
Levi Nie
Guest
Posts: n/a
 
      01-15-2013
i want to interrupt the file sending. but i can't change the client. so i
need change the server.
All things go well, but the message i wanna response seem not work.
is the self.transport.loseConnection() (the last line) blocking the
messages?
in fact, i work on Cumulus(nimbus project) which based on twisted. And i
use s3cmd as the client.

here is the my code:

def headerReceived(self,line):
pycb.log(logging.INFO, "===== def headerReceived of cumulus.py")
http.HTTPChannel.headerReceived(self,line)
pycb.log(logging.INFO, "===== self.length is %s"%self.length)

header, data = line.split(':', 1)
header = header.lower()
data = data.strip()
if header=='authorization':
self.authorization=data


if self.length and self.authorization:
user_id = self.authorization.split(':')[0].split()[1].strip()
user = pycb.config.auth.get_user(user_id)

pycb.log(logging.INFO, "===== user who put this object is
%s"%user)

remaining_quota = user.get_remaining_quota()
pycb.log(logging.INFO, "===== remaining_quota is
%s"%remaining_quota)
quota_check=self.length-remaining_quota
pycb.log(logging.INFO, "=====
quota_check=self.length-remaining_quota of cumulus.py")

if quota_check>0:
requestId = str(uuid.uuid1()).replace("-", "")
ex=cbException('AccountProblem')

m_msg = "HTTP/1.1 %s %s\r\n" % (ex.httpCode, ex.httpDesc)
self.transport.write(m_msg)

m_msg = "%s: %s\r\n" % (('x-amz-request-id', requestId))
self.transport.write(m_msg)
#req.setHeader('x-amz-request-id', requestId)

m_msg = "%s: %s\r\n" % (('x-amz-id-2', str(uuid.uuid1())))
self.transport.write(m_msg)

e_msg = ex.make_xml_string(self._path, str(uuid.uuid1()))
pycb.log(logging.INFO, "===== e_msg is %s"%e_msg)
#self.transport.write("\r\n")
self.transport.write(e_msg)
pycb.log(logging.INFO, "===== self.transport.write(e_msg)")


self.transport.loseConnection()

 
Reply With Quote
 
 
 
 
Ulrich Eckhardt
Guest
Posts: n/a
 
      01-15-2013
Am 15.01.2013 10:46, schrieb Levi Nie:
> i want to interrupt the file sending. but i can't change the client. so i
> need change the server.
> All things go well, but the message i wanna response seem not work.


Ahem, what? It doesn't work, so does it sit on the couch all day?


> is the self.transport.loseConnection() (the last line) blocking the
> messages?
> in fact, i work on Cumulus(nimbus project) which based on twisted. And i
> use s3cmd as the client.


I'm wondering if questions concerning twisted don't have a better forum.
In any case, I can only comment on the general approach. For that, there
are two things you can do:

1. When receiving the the request header, you have a content length. If
that exceeds the allowed amount, shutdown() receiving and send an
according HTTP response before closing the connection.
2. If the data exceeds the amount advertised by the content length,
close the connection and discard the request. If you want to be nice,
send an according response before closing, but I personally wouldn't go
to that effort for broken HTTP clients.

Concerning the question why your client hangs, it could also be the
sending. If you try to send something before receiving the full request,
client and server could enter a deadlock where each side waits for the
other to receive some data. For that reason, you should shutdown()
receiving in such a case.

HTH

Uli

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interrupt Component While Working With Large File & Chart to Image sherazam Java 0 02-08-2011 09:03 AM
Preferred Size, Minimum Size, Size Jason Cavett Java 5 05-25-2008 08:32 AM
VOIP over VPN over TCP over WAP over 3G Theo Markettos UK VOIP 2 02-14-2008 03:27 PM
mega pixels, file size, image size, and print size - Adobe Evangelists Frank ess Digital Photography 0 11-14-2006 05:08 PM
where can i find the core code of intel 8259A interrupt controller? Tony VHDL 0 11-13-2003 09:21 AM



Advertisments