Merge pull request #119 from Atheros1/master

use sock.sendall instead of sock.send to fix Ubuntu restart-hang issue
This commit is contained in:
Jonathan Warren 2013-04-08 22:26:45 -07:00
commit 421a52cfd6
2 changed files with 29 additions and 12 deletions

View File

@ -499,7 +499,7 @@ class receiveDataThread(QThread):
printLock.acquire() printLock.acquire()
print 'Sending huge inv message with', numberOfObjects, 'objects to just this one peer' print 'Sending huge inv message with', numberOfObjects, 'objects to just this one peer'
printLock.release() printLock.release()
self.sock.send(headerData + payload) self.sock.sendall(headerData + payload)
#We have received a broadcast message #We have received a broadcast message
def recbroadcast(self,data): def recbroadcast(self,data):
@ -1259,7 +1259,7 @@ class receiveDataThread(QThread):
headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce. headerData += pack('>L',len(payload)) #payload length. Note that we add an extra 8 for the nonce.
headerData += hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
try: try:
self.sock.send(headerData + payload) self.sock.sendall(headerData + payload)
except Exception, err: except Exception, err:
#if not 'Bad file descriptor' in err: #if not 'Bad file descriptor' in err:
printLock.acquire() printLock.acquire()
@ -1303,28 +1303,28 @@ class receiveDataThread(QThread):
headerData += 'pubkey\x00\x00\x00\x00\x00\x00' headerData += 'pubkey\x00\x00\x00\x00\x00\x00'
headerData += pack('>L',len(payload)) #payload length. headerData += pack('>L',len(payload)) #payload length.
headerData += hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.sendall(headerData + payload)
elif objectType == 'getpubkey' or objectType == 'pubkeyrequest': elif objectType == 'getpubkey' or objectType == 'pubkeyrequest':
print 'sending getpubkey' print 'sending getpubkey'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData += 'getpubkey\x00\x00\x00' headerData += 'getpubkey\x00\x00\x00'
headerData += pack('>L',len(payload)) #payload length. headerData += pack('>L',len(payload)) #payload length.
headerData += hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.sendall(headerData + payload)
elif objectType == 'msg': elif objectType == 'msg':
print 'sending msg' print 'sending msg'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData += 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00' headerData += 'msg\x00\x00\x00\x00\x00\x00\x00\x00\x00'
headerData += pack('>L',len(payload)) #payload length. headerData += pack('>L',len(payload)) #payload length.
headerData += hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.sendall(headerData + payload)
elif objectType == 'broadcast': elif objectType == 'broadcast':
print 'sending broadcast' print 'sending broadcast'
headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits. headerData = '\xe9\xbe\xb4\xd9' #magic bits, slighly different from Bitcoin's magic bits.
headerData += 'broadcast\x00\x00\x00' headerData += 'broadcast\x00\x00\x00'
headerData += pack('>L',len(payload)) #payload length. headerData += pack('>L',len(payload)) #payload length.
headerData += hashlib.sha512(payload).digest()[:4] headerData += hashlib.sha512(payload).digest()[:4]
self.sock.send(headerData + payload) self.sock.sendall(headerData + payload)
else: else:
sys.stderr.write('Error: sendData has been asked to send a strange objectType: %s\n' % str(objectType)) sys.stderr.write('Error: sendData has been asked to send a strange objectType: %s\n' % str(objectType))
@ -1534,7 +1534,7 @@ class receiveDataThread(QThread):
printLock.acquire() printLock.acquire()
print 'Sending addr with', numberOfAddressesInAddrMessage, 'entries.' print 'Sending addr with', numberOfAddressesInAddrMessage, 'entries.'
printLock.release() printLock.release()
self.sock.send(datatosend) self.sock.sendall(datatosend)
#We have received a version message #We have received a version message
def recversion(self,data): def recversion(self,data):
@ -1618,7 +1618,7 @@ class receiveDataThread(QThread):
printLock.acquire() printLock.acquire()
print 'Sending version message' print 'Sending version message'
printLock.release() printLock.release()
self.sock.send(datatosend) self.sock.sendall(datatosend)
#self.versionSent = 1 #self.versionSent = 1
#Sends a verack message #Sends a verack message
@ -1696,7 +1696,7 @@ class sendDataThread(QThread):
printLock.acquire() printLock.acquire()
print 'Sending version packet: ', repr(datatosend) print 'Sending version packet: ', repr(datatosend)
printLock.release() printLock.release()
self.sock.send(datatosend) self.sock.sendall(datatosend)
self.versionSent = 1 self.versionSent = 1
@ -4688,7 +4688,10 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetInbox.removeRow(currentRow) self.ui.tableWidgetInbox.removeRow(currentRow)
self.statusBar().showMessage('Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.') self.statusBar().showMessage('Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.')
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
if currentRow == 0:
self.ui.tableWidgetInbox.selectRow(currentRow) self.ui.tableWidgetInbox.selectRow(currentRow)
else:
self.ui.tableWidgetInbox.selectRow(currentRow-1)
#Send item on the Sent tab to trash #Send item on the Sent tab to trash
def on_action_SentTrash(self): def on_action_SentTrash(self):
@ -4705,6 +4708,11 @@ class MyForm(QtGui.QMainWindow):
self.ui.tableWidgetSent.removeRow(currentRow) self.ui.tableWidgetSent.removeRow(currentRow)
self.statusBar().showMessage('Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.') self.statusBar().showMessage('Moved items to trash. There is no user interface to view your trash, but it is still on disk if you are desperate to get it back.')
sqlSubmitQueue.put('commit') sqlSubmitQueue.put('commit')
if currentRow == 0:
self.ui.tableWidgetSent.selectRow(currentRow)
else:
self.ui.tableWidgetSent.selectRow(currentRow-1)
def on_action_SentClipboard(self): def on_action_SentClipboard(self):
currentRow = self.ui.tableWidgetSent.currentRow() currentRow = self.ui.tableWidgetSent.currentRow()
addressAtCurrentRow = str(self.ui.tableWidgetSent.item(currentRow,0).data(Qt.UserRole).toPyObject()) addressAtCurrentRow = str(self.ui.tableWidgetSent.item(currentRow,0).data(Qt.UserRole).toPyObject())

View File

@ -88,9 +88,18 @@ def takeSentMessagesOutOfTrash():
conn.commit() conn.commit()
print 'done' print 'done'
takeInboxMessagesOutOfTrash() def markAllInboxMessagesAsUnread():
item = '''update inbox set read='0' '''
parameters = ''
cur.execute(item, parameters)
output = cur.fetchall()
conn.commit()
print 'done'
#takeInboxMessagesOutOfTrash()
#takeSentMessagesOutOfTrash() #takeSentMessagesOutOfTrash()
#readInbox() #markAllInboxMessagesAsUnread()
readInbox()
#readSent() #readSent()
#readPubkeys() #readPubkeys()
#readSubscriptions() #readSubscriptions()