OSDN Git Service

libgo: Update to weekly.2012-01-15.
[pf3gnuchains/gcc-fork.git] / libgo / go / net / sockopt_windows.go
1 // Copyright 2011 The Go Authors.  All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 // Socket options for Windows
6
7 package net
8
9 import (
10         "syscall"
11 )
12
13 func setDefaultSockopts(s syscall.Handle, f, p int) {
14         switch f {
15         case syscall.AF_INET6:
16                 // Allow both IP versions even if the OS default is otherwise.
17                 syscall.SetsockoptInt(s, syscall.IPPROTO_IPV6, syscall.IPV6_V6ONLY, 0)
18         }
19
20         // Windows will reuse recently-used addresses by default.
21         // SO_REUSEADDR should not be used here, as it allows
22         // a socket to forcibly bind to a port in use by another socket.
23         // This could lead to a non-deterministic behavior, where
24         // connection requests over the port cannot be guaranteed
25         // to be handled by the correct socket.
26
27         // Allow broadcast.
28         syscall.SetsockoptInt(s, syscall.SOL_SOCKET, syscall.SO_BROADCAST, 1)
29
30 }
31
32 func setDefaultMulticastSockopts(fd *netFD) {
33         fd.incref()
34         defer fd.decref()
35         // Allow multicast UDP and raw IP datagram sockets to listen
36         // concurrently across multiple listeners.
37         syscall.SetsockoptInt(fd.sysfd, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
38 }