Bug fixes to RateLimitedOutputStream
This commit is contained in:
parent
44758aa8e2
commit
f84d2bbe55
|
@ -21,7 +21,7 @@ class RateLimitedOutputStream(out: OutputStream, bytesPerSec: Int) extends Outpu
|
|||
while (pos < length) {
|
||||
val writeSize = math.min(length - pos, CHUNK_SIZE)
|
||||
waitToWrite(writeSize)
|
||||
out.write(bytes, offset + pos, length - pos)
|
||||
out.write(bytes, offset + pos, writeSize)
|
||||
pos += writeSize
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ object RawTextSender extends Logging {
|
|||
def main(args: Array[String]) {
|
||||
if (args.length != 4) {
|
||||
System.err.println("Usage: RawTextSender <port> <file> <blockSize> <bytesPerSec>")
|
||||
System.exit(1)
|
||||
}
|
||||
// Parse the arguments using a pattern match
|
||||
val Array(IntParam(port), file, IntParam(blockSize), IntParam(bytesPerSec)) = args
|
||||
|
@ -36,6 +37,7 @@ object RawTextSender extends Logging {
|
|||
|
||||
while (true) {
|
||||
val socket = serverSocket.accept()
|
||||
logInfo("Got a new connection")
|
||||
val out = new RateLimitedOutputStream(socket.getOutputStream, bytesPerSec)
|
||||
try {
|
||||
while (true) {
|
||||
|
@ -43,7 +45,7 @@ object RawTextSender extends Logging {
|
|||
}
|
||||
} catch {
|
||||
case e: IOException =>
|
||||
logError("Socket closed: ", e)
|
||||
logError("Socket closed", e)
|
||||
socket.close()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue