Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(286)

Delta Between Two Patch Sets: src/pkg/net/fd_unix.go

Issue 6739043: net, syscall: use WriteNB on non-blocking sockets (Closed)
Left Patch Set: diff -r 7fe634e0f93e https://code.google.com/p/go Created 11 years, 5 months ago
Right Patch Set: diff -r d0ca00912d1c https://code.google.com/p/go Created 11 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/syscall/syscall_linux.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // +build darwin freebsd linux netbsd openbsd 5 // +build darwin freebsd linux netbsd openbsd
6 6
7 package net 7 package net
8 8
9 import ( 9 import (
10 "errors" 10 "errors"
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 305 }
306 netfd.cr = make(chan error, 1) 306 netfd.cr = make(chan error, 1)
307 netfd.cw = make(chan error, 1) 307 netfd.cw = make(chan error, 1)
308 netfd.pollServer = server(fd) 308 netfd.pollServer = server(fd)
309 return netfd, nil 309 return netfd, nil
310 } 310 }
311 311
312 func (fd *netFD) setAddr(laddr, raddr Addr) { 312 func (fd *netFD) setAddr(laddr, raddr Addr) {
313 fd.laddr = laddr 313 fd.laddr = laddr
314 fd.raddr = raddr 314 fd.raddr = raddr
315 » var ls, rs string 315 » fd.sysfile = os.NewFile(uintptr(fd.sysfd), fd.net)
316 » if laddr != nil {
317 » » ls = laddr.String()
318 » }
319 » if raddr != nil {
320 » » rs = raddr.String()
321 » }
322 » fd.sysfile = os.NewFile(uintptr(fd.sysfd), fd.net+":"+ls+"->"+rs)
323 } 316 }
324 317
325 func (fd *netFD) connect(ra syscall.Sockaddr) error { 318 func (fd *netFD) connect(ra syscall.Sockaddr) error {
326 err := syscall.Connect(fd.sysfd, ra) 319 err := syscall.Connect(fd.sysfd, ra)
327 if err == syscall.EINPROGRESS { 320 if err == syscall.EINPROGRESS {
328 if err = fd.pollServer.WaitWrite(fd); err != nil { 321 if err = fd.pollServer.WaitWrite(fd); err != nil {
329 return err 322 return err
330 } 323 }
331 var e int 324 var e int
332 e, err = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, sys call.SO_ERROR) 325 e, err = syscall.GetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, sys call.SO_ERROR)
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 600 }
608 defer fd.decref() 601 defer fd.decref()
609 602
610 // See ../syscall/exec_unix.go for description of ForkLock. 603 // See ../syscall/exec_unix.go for description of ForkLock.
611 // It is okay to hold the lock across syscall.Accept 604 // It is okay to hold the lock across syscall.Accept
612 // because we have put fd.sysfd into non-blocking mode. 605 // because we have put fd.sysfd into non-blocking mode.
613 var s int 606 var s int
614 var rsa syscall.Sockaddr 607 var rsa syscall.Sockaddr
615 for { 608 for {
616 syscall.ForkLock.RLock() 609 syscall.ForkLock.RLock()
617 » » s, rsa, err = syscall.Accept(fd.sysfd) 610 » » s, rsa, err = syscall.AcceptNB(fd.sysfd)
618 if err != nil { 611 if err != nil {
619 syscall.ForkLock.RUnlock() 612 syscall.ForkLock.RUnlock()
620 if err == syscall.EAGAIN { 613 if err == syscall.EAGAIN {
621 err = errTimeout 614 err = errTimeout
622 if fd.rdeadline >= 0 { 615 if fd.rdeadline >= 0 {
623 if err = fd.pollServer.WaitRead(fd); err == nil { 616 if err = fd.pollServer.WaitRead(fd); err == nil {
624 continue 617 continue
625 } 618 }
626 } 619 }
627 } else if err == syscall.ECONNABORTED { 620 } else if err == syscall.ECONNABORTED {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 if err = syscall.SetNonblock(ns, false); err != nil { 652 if err = syscall.SetNonblock(ns, false); err != nil {
660 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err} 653 return nil, &OpError{"setnonblock", fd.net, fd.laddr, err}
661 } 654 }
662 655
663 return os.NewFile(uintptr(ns), fd.sysfile.Name()), nil 656 return os.NewFile(uintptr(ns), fd.sysfile.Name()), nil
664 } 657 }
665 658
666 func closesocket(s int) error { 659 func closesocket(s int) error {
667 return syscall.Close(s) 660 return syscall.Close(s)
668 } 661 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b