Revert "Nonblocking writes to a tcp socket should not exceed send buffer size."

This reverts commit 58f17af15e34be7eed37ad35c51d562eb2c8cbf4.

Reason for revert: NET-205, flaky scp.

Change-Id: I8b2b50d5040eac82efd77ec5c1d0f9c691b7ff2d
diff --git a/tcpip/buffer/view.go b/tcpip/buffer/view.go
index d0e2570..46440cc 100644
--- a/tcpip/buffer/view.go
+++ b/tcpip/buffer/view.go
@@ -14,11 +14,6 @@
 	return make(View, size)
 }
 
-// NewViewFromBytes allocates a new buffer and copies in the given bytes.
-func NewViewFromBytes(b []byte) View {
-	return append(View(nil), b...)
-}
-
 // TrimFront removes the first "count" bytes from the visible section of the
 // buffer.
 func (v *View) TrimFront(count int) {
diff --git a/tcpip/transport/tcp/endpoint.go b/tcpip/transport/tcp/endpoint.go
index cb77f7d..1ed33f3 100644
--- a/tcpip/transport/tcp/endpoint.go
+++ b/tcpip/transport/tcp/endpoint.go
@@ -394,36 +394,27 @@
 		return 0, nil
 	}
 
+	s := newSegmentFromView(&e.route, e.id, v)
+
 	e.sndBufMu.Lock()
 
 	// Check if the connection has already been closed for sends.
 	if e.sndBufSize < 0 {
 		e.sndBufMu.Unlock()
+		s.decRef()
 		return 0, tcpip.ErrClosedForSend
 	}
 
 	// Check if we're already over the limit.
-	avail := e.sndBufSize - e.sndBufUsed
-	if avail <= 0 {
+	if e.sndBufUsed > e.sndBufSize {
 		e.sndBufMu.Unlock()
+		s.decRef()
 		return 0, tcpip.ErrWouldBlock
 	}
 
-	// If writing would put us over the size limit, create a smaller view
-	// with the maximum available size and copy into it. We also return
-	// ErrWouldBlock in this case.
-	sizedView := v
-	var err *tcpip.Error
-	if len(sizedView) > avail {
-		sizedView = buffer.NewViewFromBytes(v[:avail])
-		err = tcpip.ErrWouldBlock
-	}
-	l := len(sizedView)
-	s := newSegmentFromView(&e.route, e.id, sizedView)
-
 	// Add data to the send queue.
-	e.sndBufUsed += l
-	e.sndBufInQueue += seqnum.Size(l)
+	e.sndBufUsed += len(v)
+	e.sndBufInQueue += seqnum.Size(len(v))
 	e.sndQueue.PushBack(s)
 
 	e.sndBufMu.Unlock()
@@ -436,7 +427,8 @@
 		// Let the protocol goroutine do the work.
 		e.sndWaker.Assert()
 	}
-	return uintptr(l), err
+
+	return uintptr(len(v)), nil
 }
 
 // Peek reads data without consuming it from the endpoint.
@@ -1060,9 +1052,9 @@
 // in the send buffer. The number of newly available bytes is v.
 func (e *endpoint) updateSndBufferUsage(v int) {
 	e.sndBufMu.Lock()
-	notify := e.sndBufUsed >= e.sndBufSize
+	notify := e.sndBufUsed > e.sndBufSize
 	e.sndBufUsed -= v
-	notify = notify && e.sndBufUsed < e.sndBufSize
+	notify = notify && e.sndBufUsed <= e.sndBufSize
 	e.sndBufMu.Unlock()
 
 	if notify {