зеркало из https://github.com/CryptoPro/go.git
update code to follow new semicolon rules:
* 1. all statements and declarations are terminated by semicolons * 2. semicolons can be omitted at top level. * 3. semicolons can be omitted before and after the closing ) or } * on a list of statements or declarations. /home/rsc/bin/addsemi and then diff+tweak. R=r,gri OCL=16620 CL=16643
This commit is contained in:
Родитель
7ee60b174d
Коммит
983f06bdb6
|
@ -55,13 +55,13 @@ export func NewBufReadSize(rd io.Read, size int) (b *BufRead, err *os.Error) {
|
||||||
}
|
}
|
||||||
b = new(BufRead);
|
b = new(BufRead);
|
||||||
b.buf = new([]byte, size);
|
b.buf = new([]byte, size);
|
||||||
b.rd = rd
|
b.rd = rd;
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
export func NewBufRead(rd io.Read) (b *BufRead, err *os.Error) {
|
export func NewBufRead(rd io.Read) (b *BufRead, err *os.Error) {
|
||||||
// 6g BUG return NewBufReadSize(rd, DefaultBufSize)
|
// 6g BUG return NewBufReadSize(rd, DefaultBufSize)
|
||||||
r, e := NewBufReadSize(rd, DefaultBufSize)
|
r, e := NewBufReadSize(rd, DefaultBufSize);
|
||||||
return r, e
|
return r, e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,12 +81,12 @@ func (b *BufRead) Fill() *os.Error {
|
||||||
b.r = 0;
|
b.r = 0;
|
||||||
|
|
||||||
// Read new data.
|
// Read new data.
|
||||||
n, e := b.rd.Read(b.buf[b.w:len(b.buf)])
|
n, e := b.rd.Read(b.buf[b.w:len(b.buf)]);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
b.err = e
|
b.err = e;
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
b.w += n
|
b.w += n;
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,11 +95,11 @@ func (b *BufRead) Fill() *os.Error {
|
||||||
// If nn < len(p), also returns an error explaining
|
// If nn < len(p), also returns an error explaining
|
||||||
// why the read is short.
|
// why the read is short.
|
||||||
func (b *BufRead) Read(p *[]byte) (nn int, err *os.Error) {
|
func (b *BufRead) Read(p *[]byte) (nn int, err *os.Error) {
|
||||||
nn = 0
|
nn = 0;
|
||||||
for len(p) > 0 {
|
for len(p) > 0 {
|
||||||
n := len(p)
|
n := len(p);
|
||||||
if b.w == b.r {
|
if b.w == b.r {
|
||||||
b.Fill()
|
b.Fill();
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return nn, b.err
|
return nn, b.err
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ func (b *BufRead) Read(p *[]byte) (nn int, err *os.Error) {
|
||||||
// If no byte available, returns error.
|
// If no byte available, returns error.
|
||||||
func (b *BufRead) ReadByte() (c byte, err *os.Error) {
|
func (b *BufRead) ReadByte() (c byte, err *os.Error) {
|
||||||
if b.w == b.r {
|
if b.w == b.r {
|
||||||
b.Fill()
|
b.Fill();
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return 0, b.err
|
return 0, b.err
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ func (b *BufRead) ReadByte() (c byte, err *os.Error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c = b.buf[b.r];
|
c = b.buf[b.r];
|
||||||
b.r++
|
b.r++;
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ func (b *BufRead) UnreadByte() *os.Error {
|
||||||
if b.r <= 0 {
|
if b.r <= 0 {
|
||||||
return PhaseError
|
return PhaseError
|
||||||
}
|
}
|
||||||
b.r--
|
b.r--;
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ func (b *BufRead) ReadLineSlice(delim byte) (line *[]byte, err *os.Error) {
|
||||||
// Search new part of buffer
|
// Search new part of buffer
|
||||||
if i := FindByte(b.buf[n:b.w], delim); i >= 0 {
|
if i := FindByte(b.buf[n:b.w], delim); i >= 0 {
|
||||||
line := b.buf[0:n+i+1];
|
line := b.buf[0:n+i+1];
|
||||||
b.r = n+i+1
|
b.r = n+i+1;
|
||||||
return line, nil
|
return line, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,12 +243,12 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
|
||||||
n, e = b.Read(buf);
|
n, e = b.Read(buf);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
frag = buf[0:n];
|
frag = buf[0:n];
|
||||||
err = e
|
err = e;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if n != len(buf) {
|
if n != len(buf) {
|
||||||
frag = buf[0:n];
|
frag = buf[0:n];
|
||||||
err = InternalError
|
err = InternalError;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,11 +266,11 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
|
||||||
|
|
||||||
// Save buffer
|
// Save buffer
|
||||||
full[nfull] = buf;
|
full[nfull] = buf;
|
||||||
nfull++
|
nfull++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate new buffer to hold the full pieces and the fragment.
|
// Allocate new buffer to hold the full pieces and the fragment.
|
||||||
n := 0
|
n := 0;
|
||||||
for i := 0; i < nfull; i++ {
|
for i := 0; i < nfull; i++ {
|
||||||
n += len(full[i])
|
n += len(full[i])
|
||||||
}
|
}
|
||||||
|
@ -280,7 +280,7 @@ func (b *BufRead) ReadLineBytes(delim byte) (line *[]byte, err *os.Error) {
|
||||||
|
|
||||||
// Copy full pieces and fragment in.
|
// Copy full pieces and fragment in.
|
||||||
buf := new([]byte, n);
|
buf := new([]byte, n);
|
||||||
n = 0
|
n = 0;
|
||||||
for i := 0; i < nfull; i++ {
|
for i := 0; i < nfull; i++ {
|
||||||
CopySlice(buf[n:n+len(full[i])], full[i]);
|
CopySlice(buf[n:n+len(full[i])], full[i]);
|
||||||
n += len(full[i])
|
n += len(full[i])
|
||||||
|
@ -303,7 +303,7 @@ func ToString(p *[]byte) string {
|
||||||
// returning a new string containing the line.
|
// returning a new string containing the line.
|
||||||
// If savedelim, keep delim in the result; otherwise chop it off.
|
// If savedelim, keep delim in the result; otherwise chop it off.
|
||||||
func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) {
|
func (b *BufRead) ReadLineString(delim byte, savedelim bool) (line string, err *os.Error) {
|
||||||
bytes, e := b.ReadLineBytes(delim)
|
bytes, e := b.ReadLineBytes(delim);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return ToString(bytes), e
|
return ToString(bytes), e
|
||||||
}
|
}
|
||||||
|
@ -329,13 +329,13 @@ export func NewBufWriteSize(wr io.Write, size int) (b *BufWrite, err *os.Error)
|
||||||
}
|
}
|
||||||
b = new(BufWrite);
|
b = new(BufWrite);
|
||||||
b.buf = new([]byte, size);
|
b.buf = new([]byte, size);
|
||||||
b.wr = wr
|
b.wr = wr;
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
export func NewBufWrite(wr io.Write) (b *BufWrite, err *os.Error) {
|
export func NewBufWrite(wr io.Write) (b *BufWrite, err *os.Error) {
|
||||||
// 6g BUG return NewBufWriteSize(wr, DefaultBufSize)
|
// 6g BUG return NewBufWriteSize(wr, DefaultBufSize)
|
||||||
r, e := NewBufWriteSize(wr, DefaultBufSize)
|
r, e := NewBufWriteSize(wr, DefaultBufSize);
|
||||||
return r, e
|
return r, e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,10 +344,10 @@ func (b *BufWrite) Flush() *os.Error {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return b.err
|
return b.err
|
||||||
}
|
}
|
||||||
n := 0
|
n := 0;
|
||||||
for n < b.n {
|
for n < b.n {
|
||||||
m, e := b.wr.Write(b.buf[n:b.n]);
|
m, e := b.wr.Write(b.buf[n:b.n]);
|
||||||
n += m
|
n += m;
|
||||||
if m == 0 && e == nil {
|
if m == 0 && e == nil {
|
||||||
e = ShortWrite
|
e = ShortWrite
|
||||||
}
|
}
|
||||||
|
@ -356,11 +356,11 @@ func (b *BufWrite) Flush() *os.Error {
|
||||||
CopySlice(b.buf[0:b.n-n], b.buf[n:b.n])
|
CopySlice(b.buf[0:b.n-n], b.buf[n:b.n])
|
||||||
}
|
}
|
||||||
b.n -= n;
|
b.n -= n;
|
||||||
b.err = e
|
b.err = e;
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.n = 0
|
b.n = 0;
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,9 +376,9 @@ func (b *BufWrite) Write(p *[]byte) (nn int, err *os.Error) {
|
||||||
if b.err != nil {
|
if b.err != nil {
|
||||||
return 0, b.err
|
return 0, b.err
|
||||||
}
|
}
|
||||||
nn = 0
|
nn = 0;
|
||||||
for len(p) > 0 {
|
for len(p) > 0 {
|
||||||
n := b.Available()
|
n := b.Available();
|
||||||
if n <= 0 {
|
if n <= 0 {
|
||||||
if b.Flush(); b.err != nil {
|
if b.Flush(); b.err != nil {
|
||||||
break
|
break
|
||||||
|
@ -404,7 +404,7 @@ func (b *BufWrite) WriteByte(c byte) *os.Error {
|
||||||
return b.err
|
return b.err
|
||||||
}
|
}
|
||||||
b.buf[b.n] = c;
|
b.buf[b.n] = c;
|
||||||
b.n++
|
b.n++;
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,13 +71,13 @@ func atoi(s string) (value int64, ok bool) {
|
||||||
var base int64 = 10;
|
var base int64 = 10;
|
||||||
i := 0;
|
i := 0;
|
||||||
if s[0] == '0' {
|
if s[0] == '0' {
|
||||||
base = 8
|
base = 8;
|
||||||
if len(s) > 1 && (s[1] == 'x' || s[1] == 'X') {
|
if len(s) > 1 && (s[1] == 'x' || s[1] == 'X') {
|
||||||
base = 16;
|
base = 16;
|
||||||
i += 2;
|
i += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var n int64 = 0
|
var n int64 = 0;
|
||||||
for ; i < len(s); i++ {
|
for ; i < len(s); i++ {
|
||||||
k := ctoi(int64(s[i]));
|
k := ctoi(int64(s[i]));
|
||||||
if k >= base {
|
if k >= base {
|
||||||
|
@ -91,7 +91,7 @@ func atoi(s string) (value int64, ok bool) {
|
||||||
func atob(str string) (value bool, ok bool) {
|
func atob(str string) (value bool, ok bool) {
|
||||||
switch str {
|
switch str {
|
||||||
case "1", "t", "T", "true", "TRUE", "True":
|
case "1", "t", "T", "true", "TRUE", "True":
|
||||||
return true, true
|
return true, true;
|
||||||
case "0", "f", "F", "false", "FALSE", "False":
|
case "0", "f", "F", "false", "FALSE", "False":
|
||||||
return false, true
|
return false, true
|
||||||
}
|
}
|
||||||
|
@ -395,7 +395,7 @@ func (f *Flags) ParseOne(index int) (ok bool, next int)
|
||||||
return false, -1
|
return false, -1
|
||||||
}
|
}
|
||||||
if s[1] == '-' {
|
if s[1] == '-' {
|
||||||
num_minuses++
|
num_minuses++;
|
||||||
if len(s) == 2 { // "--" terminates the flags
|
if len(s) == 2 { // "--" terminates the flags
|
||||||
return false, index + 1
|
return false, index + 1
|
||||||
}
|
}
|
||||||
|
@ -456,7 +456,7 @@ func (f *Flags) ParseOne(index int) (ok bool, next int)
|
||||||
print("invalid integer value ", value, " for flag: -", name, "\n");
|
print("invalid integer value ", value, " for flag: -", name, "\n");
|
||||||
Usage();
|
Usage();
|
||||||
}
|
}
|
||||||
flag.value.AsInt().Set(k)
|
flag.value.AsInt().Set(k);
|
||||||
case flag.value.IsString():
|
case flag.value.IsString():
|
||||||
if !has_value {
|
if !has_value {
|
||||||
print("flag needs an argument: -", name, "\n");
|
print("flag needs an argument: -", name, "\n");
|
||||||
|
|
|
@ -20,11 +20,11 @@ export type ReadWrite interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func WriteString(w Write, s string) (n int, err *os.Error) {
|
export func WriteString(w Write, s string) (n int, err *os.Error) {
|
||||||
b := new([]byte, len(s)+1)
|
b := new([]byte, len(s)+1);
|
||||||
if !syscall.StringToBytes(b, s) {
|
if !syscall.StringToBytes(b, s) {
|
||||||
return -1, os.EINVAL
|
return -1, os.EINVAL
|
||||||
}
|
}
|
||||||
// BUG return w.Write(b[0:len(s)])
|
// BUG return w.Write(b[0:len(s)])
|
||||||
r, e := w.Write(b[0:len(s)])
|
r, e := w.Write(b[0:len(s)]);
|
||||||
return r, e
|
return r, e
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,11 @@ export type FD struct {
|
||||||
|
|
||||||
// Make reads and writes on fd return EAGAIN instead of blocking.
|
// Make reads and writes on fd return EAGAIN instead of blocking.
|
||||||
func SetNonblock(fd int64) *os.Error {
|
func SetNonblock(fd int64) *os.Error {
|
||||||
flags, e := syscall.fcntl(fd, syscall.F_GETFL, 0)
|
flags, e := syscall.fcntl(fd, syscall.F_GETFL, 0);
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
return os.ErrnoToError(e)
|
return os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
flags, e = syscall.fcntl(fd, syscall.F_SETFL, flags | syscall.O_NONBLOCK)
|
flags, e = syscall.fcntl(fd, syscall.F_SETFL, flags | syscall.O_NONBLOCK);
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
return os.ErrnoToError(e)
|
return os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ func NewPollServer() (s *PollServer, err *os.Error) {
|
||||||
if err = SetNonblock(s.pr.fd); err != nil {
|
if err = SetNonblock(s.pr.fd); err != nil {
|
||||||
Error:
|
Error:
|
||||||
s.pr.Close();
|
s.pr.Close();
|
||||||
s.pw.Close()
|
s.pw.Close();
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if err = SetNonblock(s.pw.fd); err != nil {
|
if err = SetNonblock(s.pw.fd); err != nil {
|
||||||
|
@ -97,40 +97,40 @@ func NewPollServer() (s *PollServer, err *os.Error) {
|
||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
if err = s.poll.AddFD(s.pr.fd, 'r', true); err != nil {
|
if err = s.poll.AddFD(s.pr.fd, 'r', true); err != nil {
|
||||||
s.poll.Close()
|
s.poll.Close();
|
||||||
goto Error
|
goto Error
|
||||||
}
|
}
|
||||||
s.pending = new(map[int64] *FD)
|
s.pending = new(map[int64] *FD);
|
||||||
go s.Run()
|
go s.Run();
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PollServer) AddFD(fd *FD, mode int) {
|
func (s *PollServer) AddFD(fd *FD, mode int) {
|
||||||
if err := s.poll.AddFD(fd.fd, mode, false); err != nil {
|
if err := s.poll.AddFD(fd.fd, mode, false); err != nil {
|
||||||
print("PollServer AddFD: ", err.String(), "\n")
|
print("PollServer AddFD: ", err.String(), "\n");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
key := fd.fd << 1
|
key := fd.fd << 1;
|
||||||
if mode == 'r' {
|
if mode == 'r' {
|
||||||
fd.ncr++
|
fd.ncr++;
|
||||||
} else {
|
} else {
|
||||||
fd.ncw++
|
fd.ncw++;
|
||||||
key++
|
key++;
|
||||||
}
|
}
|
||||||
s.pending[key] = fd
|
s.pending[key] = fd
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PollServer) LookupFD(fd int64, mode int) *FD {
|
func (s *PollServer) LookupFD(fd int64, mode int) *FD {
|
||||||
key := fd << 1
|
key := fd << 1;
|
||||||
if mode == 'w' {
|
if mode == 'w' {
|
||||||
key++
|
key++;
|
||||||
}
|
}
|
||||||
netfd, ok := s.pending[key]
|
netfd, ok := s.pending[key];
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
s.pending[key] = nil, false
|
s.pending[key] = nil, false;
|
||||||
return netfd
|
return netfd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +139,7 @@ func (s *PollServer) Run() {
|
||||||
for {
|
for {
|
||||||
fd, mode, err := s.poll.WaitFD();
|
fd, mode, err := s.poll.WaitFD();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print("PollServer WaitFD: ", err.String(), "\n")
|
print("PollServer WaitFD: ", err.String(), "\n");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if fd == s.pr.fd {
|
if fd == s.pr.fd {
|
||||||
|
@ -156,19 +156,19 @@ func (s *PollServer) Run() {
|
||||||
s.AddFD(fd, 'w')
|
s.AddFD(fd, 'w')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
netfd := s.LookupFD(fd, mode)
|
netfd := s.LookupFD(fd, mode);
|
||||||
if netfd == nil {
|
if netfd == nil {
|
||||||
print("PollServer: unexpected wakeup for fd=", netfd, " mode=", string(mode), "\n")
|
print("PollServer: unexpected wakeup for fd=", netfd, " mode=", string(mode), "\n");
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if mode == 'r' {
|
if mode == 'r' {
|
||||||
for netfd.ncr > 0 {
|
for netfd.ncr > 0 {
|
||||||
netfd.ncr--
|
netfd.ncr--;
|
||||||
netfd.cr <- netfd
|
netfd.cr <- netfd
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for netfd.ncw > 0 {
|
for netfd.ncw > 0 {
|
||||||
netfd.ncw--
|
netfd.ncw--;
|
||||||
netfd.cw <- netfd
|
netfd.cw <- netfd
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +200,7 @@ func (s *PollServer) WaitWrite(fd *FD) {
|
||||||
var pollserver *PollServer
|
var pollserver *PollServer
|
||||||
|
|
||||||
func StartServer() {
|
func StartServer() {
|
||||||
p, err := NewPollServer()
|
p, err := NewPollServer();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
print("Start PollServer: ", err.String(), "\n")
|
print("Start PollServer: ", err.String(), "\n")
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ func (fd *FD) Close() *os.Error {
|
||||||
}
|
}
|
||||||
e := fd.osfd.Close();
|
e := fd.osfd.Close();
|
||||||
fd.osfd = nil;
|
fd.osfd = nil;
|
||||||
fd.fd = -1
|
fd.fd = -1;
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ func (fd *FD) Read(p *[]byte) (n int, err *os.Error) {
|
||||||
if fd == nil || fd.osfd == nil {
|
if fd == nil || fd.osfd == nil {
|
||||||
return -1, os.EINVAL
|
return -1, os.EINVAL
|
||||||
}
|
}
|
||||||
n, err = fd.osfd.Read(p)
|
n, err = fd.osfd.Read(p);
|
||||||
for err == os.EAGAIN {
|
for err == os.EAGAIN {
|
||||||
pollserver.WaitRead(fd);
|
pollserver.WaitRead(fd);
|
||||||
n, err = fd.osfd.Read(p)
|
n, err = fd.osfd.Read(p)
|
||||||
|
@ -249,7 +249,7 @@ func (fd *FD) Write(p *[]byte) (n int, err *os.Error) {
|
||||||
return -1, os.EINVAL
|
return -1, os.EINVAL
|
||||||
}
|
}
|
||||||
err = nil;
|
err = nil;
|
||||||
nn := 0
|
nn := 0;
|
||||||
for nn < len(p) && err == nil {
|
for nn < len(p) && err == nil {
|
||||||
n, err = fd.osfd.Write(p[nn:len(p)]);
|
n, err = fd.osfd.Write(p[nn:len(p)]);
|
||||||
for err == os.EAGAIN {
|
for err == os.EAGAIN {
|
||||||
|
@ -270,7 +270,7 @@ func (fd *FD) Accept(sa *syscall.Sockaddr) (nfd *FD, err *os.Error) {
|
||||||
if fd == nil || fd.osfd == nil {
|
if fd == nil || fd.osfd == nil {
|
||||||
return nil, os.EINVAL
|
return nil, os.EINVAL
|
||||||
}
|
}
|
||||||
s, e := syscall.accept(fd.fd, sa)
|
s, e := syscall.accept(fd.fd, sa);
|
||||||
for e == syscall.EAGAIN {
|
for e == syscall.EAGAIN {
|
||||||
pollserver.WaitRead(fd);
|
pollserver.WaitRead(fd);
|
||||||
s, e = syscall.accept(fd.fd, sa)
|
s, e = syscall.accept(fd.fd, sa)
|
||||||
|
@ -279,7 +279,7 @@ func (fd *FD) Accept(sa *syscall.Sockaddr) (nfd *FD, err *os.Error) {
|
||||||
return nil, os.ErrnoToError(e)
|
return nil, os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
if nfd, err = NewFD(s); err != nil {
|
if nfd, err = NewFD(s); err != nil {
|
||||||
syscall.close(s)
|
syscall.close(s);
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nfd, nil
|
return nfd, nil
|
||||||
|
|
|
@ -24,7 +24,7 @@ export func NewPollster() (p *Pollster, err *os.Error) {
|
||||||
if p.kq, e = syscall.kqueue(); e != 0 {
|
if p.kq, e = syscall.kqueue(); e != 0 {
|
||||||
return nil, os.ErrnoToError(e)
|
return nil, os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
p.events = (&p.eventbuf)[0:0]
|
p.events = (&p.eventbuf)[0:0];
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
|
||||||
// EV_RECEIPT - generate fake EV_ERROR as result of add,
|
// EV_RECEIPT - generate fake EV_ERROR as result of add,
|
||||||
// rather than waiting for real event
|
// rather than waiting for real event
|
||||||
// EV_ONESHOT - delete the event the first time it triggers
|
// EV_ONESHOT - delete the event the first time it triggers
|
||||||
ev.flags = syscall.EV_ADD | syscall.EV_RECEIPT
|
ev.flags = syscall.EV_ADD | syscall.EV_RECEIPT;
|
||||||
if !repeat {
|
if !repeat {
|
||||||
ev.flags |= syscall.EV_ONESHOT
|
ev.flags |= syscall.EV_ONESHOT
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
|
||||||
|
|
||||||
func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
|
func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
|
||||||
for len(p.events) == 0 {
|
for len(p.events) == 0 {
|
||||||
nn, e := syscall.kevent(p.kq, nil, &p.eventbuf, nil)
|
nn, e := syscall.kevent(p.kq, nil, &p.eventbuf, nil);
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
if e == syscall.EAGAIN || e == syscall.EINTR {
|
if e == syscall.EAGAIN || e == syscall.EINTR {
|
||||||
continue
|
continue
|
||||||
|
@ -85,6 +85,6 @@ func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pollster) Close() *os.Error {
|
func (p *Pollster) Close() *os.Error {
|
||||||
r, e := syscall.close(p.kq)
|
r, e := syscall.close(p.kq);
|
||||||
return os.ErrnoToError(e)
|
return os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ export func NewPollster() (p *Pollster, err *os.Error) {
|
||||||
if p.epfd, e = syscall.epoll_create(16); e != 0 {
|
if p.epfd, e = syscall.epoll_create(16); e != 0 {
|
||||||
return nil, os.ErrnoToError(e)
|
return nil, os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
p.events = new(map[int64] uint)
|
p.events = new(map[int64] uint);
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
|
||||||
var ev syscall.EpollEvent
|
var ev syscall.EpollEvent
|
||||||
var already bool;
|
var already bool;
|
||||||
ev.fd = int32(fd);
|
ev.fd = int32(fd);
|
||||||
ev.events, already = p.events[fd]
|
ev.events, already = p.events[fd];
|
||||||
if !repeat {
|
if !repeat {
|
||||||
ev.events |= syscall.EPOLLONESHOT
|
ev.events |= syscall.EPOLLONESHOT
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
|
||||||
ev.events |= Write
|
ev.events |= Write
|
||||||
}
|
}
|
||||||
|
|
||||||
var op int64
|
var op int64;
|
||||||
if already {
|
if already {
|
||||||
op = syscall.EPOLL_CTL_MOD
|
op = syscall.EPOLL_CTL_MOD
|
||||||
} else {
|
} else {
|
||||||
|
@ -61,14 +61,14 @@ func (p *Pollster) AddFD(fd int64, mode int, repeat bool) *os.Error {
|
||||||
if e := syscall.epoll_ctl(p.epfd, op, fd, &ev); e != 0 {
|
if e := syscall.epoll_ctl(p.epfd, op, fd, &ev); e != 0 {
|
||||||
return os.ErrnoToError(e)
|
return os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
p.events[fd] = ev.events
|
p.events[fd] = ev.events;
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pollster) StopWaiting(fd int64, bits uint) {
|
func (p *Pollster) StopWaiting(fd int64, bits uint) {
|
||||||
events, already := p.events[fd]
|
events, already := p.events[fd];
|
||||||
if !already {
|
if !already {
|
||||||
print("Epoll unexpected fd=", fd, "\n")
|
print("Epoll unexpected fd=", fd, "\n");
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func (p *Pollster) StopWaiting(fd int64, bits uint) {
|
||||||
// Disable the given bits.
|
// Disable the given bits.
|
||||||
// If we're still waiting for other events, modify the fd
|
// If we're still waiting for other events, modify the fd
|
||||||
// event in the kernel. Otherwise, delete it.
|
// event in the kernel. Otherwise, delete it.
|
||||||
events &= ^bits
|
events &= ^bits;
|
||||||
if int32(events) & ^syscall.EPOLLONESHOT != 0 {
|
if int32(events) & ^syscall.EPOLLONESHOT != 0 {
|
||||||
var ev syscall.EpollEvent;
|
var ev syscall.EpollEvent;
|
||||||
ev.fd = int32(fd);
|
ev.fd = int32(fd);
|
||||||
|
@ -102,35 +102,35 @@ func (p *Pollster) WaitFD() (fd int64, mode int, err *os.Error) {
|
||||||
// Get an event.
|
// Get an event.
|
||||||
var evarray [1]syscall.EpollEvent;
|
var evarray [1]syscall.EpollEvent;
|
||||||
ev := &evarray[0];
|
ev := &evarray[0];
|
||||||
n, e := syscall.epoll_wait(p.epfd, &evarray, -1)
|
n, e := syscall.epoll_wait(p.epfd, &evarray, -1);
|
||||||
for e == syscall.EAGAIN || e == syscall.EINTR {
|
for e == syscall.EAGAIN || e == syscall.EINTR {
|
||||||
n, e = syscall.epoll_wait(p.epfd, &evarray, -1)
|
n, e = syscall.epoll_wait(p.epfd, &evarray, -1)
|
||||||
}
|
}
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
return -1, 0, os.ErrnoToError(e)
|
return -1, 0, os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
fd = int64(ev.fd)
|
fd = int64(ev.fd);
|
||||||
|
|
||||||
if ev.events & Write != 0 {
|
if ev.events & Write != 0 {
|
||||||
p.StopWaiting(fd, Write)
|
p.StopWaiting(fd, Write);
|
||||||
return fd, 'w', nil
|
return fd, 'w', nil
|
||||||
}
|
}
|
||||||
if ev.events & Read != 0 {
|
if ev.events & Read != 0 {
|
||||||
p.StopWaiting(fd, Read)
|
p.StopWaiting(fd, Read);
|
||||||
return fd, 'r', nil
|
return fd, 'r', nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Other events are error conditions - wake whoever is waiting.
|
// Other events are error conditions - wake whoever is waiting.
|
||||||
events, already := p.events[fd]
|
events, already := p.events[fd];
|
||||||
if events & Write != 0 {
|
if events & Write != 0 {
|
||||||
p.StopWaiting(fd, Write)
|
p.StopWaiting(fd, Write);
|
||||||
return fd, 'w', nil
|
return fd, 'w', nil
|
||||||
}
|
}
|
||||||
p.StopWaiting(fd, Read)
|
p.StopWaiting(fd, Read);
|
||||||
return fd, 'r', nil
|
return fd, 'r', nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pollster) Close() *os.Error {
|
func (p *Pollster) Close() *os.Error {
|
||||||
r, e := syscall.close(p.epfd)
|
r, e := syscall.close(p.epfd);
|
||||||
return os.ErrnoToError(e)
|
return os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ export const (
|
||||||
|
|
||||||
// Make the 4 bytes into an IPv4 address (in IPv6 form)
|
// Make the 4 bytes into an IPv4 address (in IPv6 form)
|
||||||
func MakeIPv4(a, b, c, d byte) *[]byte {
|
func MakeIPv4(a, b, c, d byte) *[]byte {
|
||||||
p := new([]byte, IPv6len)
|
p := new([]byte, IPv6len);
|
||||||
for i := 0; i < 10; i++ {
|
for i := 0; i < 10; i++ {
|
||||||
p[i] = 0
|
p[i] = 0
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func MakeIPv4(a, b, c, d byte) *[]byte {
|
||||||
p[12] = a;
|
p[12] = a;
|
||||||
p[13] = b;
|
p[13] = b;
|
||||||
p[14] = c;
|
p[14] = c;
|
||||||
p[15] = d
|
p[15] = d;
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,11 +107,11 @@ export func DefaultMask(p *[]byte) *[]byte {
|
||||||
|
|
||||||
// Apply mask to ip, returning new address.
|
// Apply mask to ip, returning new address.
|
||||||
export func Mask(ip *[]byte, mask *[]byte) *[]byte {
|
export func Mask(ip *[]byte, mask *[]byte) *[]byte {
|
||||||
n := len(ip)
|
n := len(ip);
|
||||||
if n != len(mask) {
|
if n != len(mask) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
out := new([]byte, n)
|
out := new([]byte, n);
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
out[i] = ip[i] & mask[i];
|
out[i] = ip[i] & mask[i];
|
||||||
}
|
}
|
||||||
|
@ -169,9 +169,9 @@ export func IPToString(p *[]byte) string {
|
||||||
|
|
||||||
// Find longest run of zeros.
|
// Find longest run of zeros.
|
||||||
e0 := -1;
|
e0 := -1;
|
||||||
e1 := -1
|
e1 := -1;
|
||||||
for i := 0; i < 16; i+=2 {
|
for i := 0; i < 16; i+=2 {
|
||||||
j := i
|
j := i;
|
||||||
for j < 16 && p[j] == 0 && p[j+1] == 0 {
|
for j < 16 && p[j] == 0 && p[j+1] == 0 {
|
||||||
j += 2
|
j += 2
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ export func IPToString(p *[]byte) string {
|
||||||
for i := 0; i < 16; i += 2 {
|
for i := 0; i < 16; i += 2 {
|
||||||
if i == e0 {
|
if i == e0 {
|
||||||
s += "::";
|
s += "::";
|
||||||
i = e1
|
i = e1;
|
||||||
if i >= 16 {
|
if i >= 16 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -201,16 +201,16 @@ export func IPToString(p *[]byte) string {
|
||||||
// If mask is a sequence of 1 bits followed by 0 bits,
|
// If mask is a sequence of 1 bits followed by 0 bits,
|
||||||
// return the number of 1 bits.
|
// return the number of 1 bits.
|
||||||
func SimpleMaskLength(mask *[]byte) int {
|
func SimpleMaskLength(mask *[]byte) int {
|
||||||
var i int
|
var i int;
|
||||||
for i = 0; i < len(mask); i++ {
|
for i = 0; i < len(mask); i++ {
|
||||||
if mask[i] != 0xFF {
|
if mask[i] != 0xFF {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n := 8*i;
|
n := 8*i;
|
||||||
v := mask[i]
|
v := mask[i];
|
||||||
for v & 0x80 != 0 {
|
for v & 0x80 != 0 {
|
||||||
n++
|
n++;
|
||||||
v <<= 1
|
v <<= 1
|
||||||
}
|
}
|
||||||
if v != 0 {
|
if v != 0 {
|
||||||
|
@ -227,12 +227,12 @@ func SimpleMaskLength(mask *[]byte) int {
|
||||||
export func MaskToString(mask *[]byte) string {
|
export func MaskToString(mask *[]byte) string {
|
||||||
switch len(mask) {
|
switch len(mask) {
|
||||||
case 4:
|
case 4:
|
||||||
n := SimpleMaskLength(mask)
|
n := SimpleMaskLength(mask);
|
||||||
if n >= 0 {
|
if n >= 0 {
|
||||||
return itod(uint(n+(IPv6len-IPv4len)*8))
|
return itod(uint(n+(IPv6len-IPv4len)*8))
|
||||||
}
|
}
|
||||||
case 16:
|
case 16:
|
||||||
n := SimpleMaskLength(mask)
|
n := SimpleMaskLength(mask);
|
||||||
if n >= 0 {
|
if n >= 0 {
|
||||||
return itod(uint(n))
|
return itod(uint(n))
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ func dtoi(s string, i int) (n int, i1 int, ok bool) {
|
||||||
}
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
for ; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
for ; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
||||||
n = n*10 + int(s[i] - '0')
|
n = n*10 + int(s[i] - '0');
|
||||||
if n >= Big {
|
if n >= Big {
|
||||||
return 0, i, false
|
return 0, i, false
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ func xtoi(s string, i int) (n int, i1 int, ok bool) {
|
||||||
|
|
||||||
n = 0;
|
n = 0;
|
||||||
for ; i < len(s) && ishex(s[i]); i++ {
|
for ; i < len(s) && ishex(s[i]); i++ {
|
||||||
n *= 16
|
n *= 16;
|
||||||
if '0' <= s[i] && s[i] <= '9' {
|
if '0' <= s[i] && s[i] <= '9' {
|
||||||
n += int(s[i] - '0')
|
n += int(s[i] - '0')
|
||||||
} else if 'a' <= s[i] && s[i] <= 'f' {
|
} else if 'a' <= s[i] && s[i] <= 'f' {
|
||||||
|
@ -294,20 +294,20 @@ func xtoi(s string, i int) (n int, i1 int, ok bool) {
|
||||||
|
|
||||||
// Parse IPv4 address (d.d.d.d).
|
// Parse IPv4 address (d.d.d.d).
|
||||||
func ParseIPv4(s string) *[]byte {
|
func ParseIPv4(s string) *[]byte {
|
||||||
var p [IPv4len]byte
|
var p [IPv4len]byte;
|
||||||
i := 0
|
i := 0;
|
||||||
for j := 0; j < IPv4len; j++ {
|
for j := 0; j < IPv4len; j++ {
|
||||||
if j > 0 {
|
if j > 0 {
|
||||||
if s[i] != '.' {
|
if s[i] != '.' {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
i++
|
i++;
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
n int;
|
n int;
|
||||||
ok bool
|
ok bool
|
||||||
)
|
)
|
||||||
n, i, ok = dtoi(s, i)
|
n, i, ok = dtoi(s, i);
|
||||||
if !ok || n > 0xFF {
|
if !ok || n > 0xFF {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -335,7 +335,7 @@ func ParseIPv6(s string) *[]byte {
|
||||||
// Might have leading ellipsis
|
// Might have leading ellipsis
|
||||||
if len(s) >= 2 && s[0] == ':' && s[1] == ':' {
|
if len(s) >= 2 && s[0] == ':' && s[1] == ':' {
|
||||||
ellipsis = 0;
|
ellipsis = 0;
|
||||||
i = 2
|
i = 2;
|
||||||
// Might be only ellipsis
|
// Might be only ellipsis
|
||||||
if i == len(s) {
|
if i == len(s) {
|
||||||
return p
|
return p
|
||||||
|
@ -346,7 +346,7 @@ func ParseIPv6(s string) *[]byte {
|
||||||
j := 0;
|
j := 0;
|
||||||
L: for j < IPv6len {
|
L: for j < IPv6len {
|
||||||
// Hex number.
|
// Hex number.
|
||||||
n, i1, ok := xtoi(s, i)
|
n, i1, ok := xtoi(s, i);
|
||||||
if !ok || n > 0xFFFF {
|
if !ok || n > 0xFFFF {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -371,7 +371,7 @@ L: for j < IPv6len {
|
||||||
p[j+2] = p4[14];
|
p[j+2] = p4[14];
|
||||||
p[j+3] = p4[15];
|
p[j+3] = p4[15];
|
||||||
i = len(s);
|
i = len(s);
|
||||||
j += 4
|
j += 4;
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ L: for j < IPv6len {
|
||||||
j += 2;
|
j += 2;
|
||||||
|
|
||||||
// Stop at end of string.
|
// Stop at end of string.
|
||||||
i = i1
|
i = i1;
|
||||||
if i == len(s) {
|
if i == len(s) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ L: for j < IPv6len {
|
||||||
if s[i] != ':' && i+1 == len(s) {
|
if s[i] != ':' && i+1 == len(s) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
i++
|
i++;
|
||||||
|
|
||||||
// Look for ellipsis.
|
// Look for ellipsis.
|
||||||
if s[i] == ':' {
|
if s[i] == ':' {
|
||||||
|
@ -414,7 +414,7 @@ L: for j < IPv6len {
|
||||||
if ellipsis < 0 {
|
if ellipsis < 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
n := IPv6len - j
|
n := IPv6len - j;
|
||||||
for k := j-1; k >= ellipsis; k-- {
|
for k := j-1; k >= ellipsis; k-- {
|
||||||
p[k+n] = p[k]
|
p[k+n] = p[k]
|
||||||
}
|
}
|
||||||
|
@ -426,7 +426,7 @@ L: for j < IPv6len {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func ParseIP(s string) *[]byte {
|
export func ParseIP(s string) *[]byte {
|
||||||
p := ParseIPv4(s)
|
p := ParseIPv4(s);
|
||||||
if p != nil {
|
if p != nil {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ export var (
|
||||||
// Host cannot contain colons unless it is bracketed.
|
// Host cannot contain colons unless it is bracketed.
|
||||||
func SplitHostPort(hostport string) (host, port string, err *os.Error) {
|
func SplitHostPort(hostport string) (host, port string, err *os.Error) {
|
||||||
// The port starts after the last colon.
|
// The port starts after the last colon.
|
||||||
var i int
|
var i int;
|
||||||
for i = len(hostport)-1; i >= 0; i-- {
|
for i = len(hostport)-1; i >= 0; i-- {
|
||||||
if hostport[i] == ':' {
|
if hostport[i] == ':' {
|
||||||
break
|
break
|
||||||
|
@ -69,7 +69,7 @@ func xdtoi(s string) (n int, ok bool) {
|
||||||
}
|
}
|
||||||
n = 0;
|
n = 0;
|
||||||
for i := 0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
for i := 0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
|
||||||
n = n*10 + int(s[i] - '0')
|
n = n*10 + int(s[i] - '0');
|
||||||
if n >= 1000000 { // bigger than we need
|
if n >= 1000000 { // bigger than we need
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
@ -108,12 +108,12 @@ func HostPortToIP(net string, hostport string) (ip *[]byte, iport int, err *os.E
|
||||||
func SockaddrToHostPort(sa *syscall.Sockaddr) (hostport string, err *os.Error) {
|
func SockaddrToHostPort(sa *syscall.Sockaddr) (hostport string, err *os.Error) {
|
||||||
switch sa.family {
|
switch sa.family {
|
||||||
case syscall.AF_INET, syscall.AF_INET6:
|
case syscall.AF_INET, syscall.AF_INET6:
|
||||||
addr, port, e := SockaddrToIP(sa)
|
addr, port, e := SockaddrToIP(sa);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", e
|
return "", e
|
||||||
}
|
}
|
||||||
host := IPToString(addr);
|
host := IPToString(addr);
|
||||||
return JoinHostPort(host, strings.itoa(port)), nil
|
return JoinHostPort(host, strings.itoa(port)), nil;
|
||||||
default:
|
default:
|
||||||
return "", UnknownSocketFamily
|
return "", UnknownSocketFamily
|
||||||
}
|
}
|
||||||
|
@ -136,28 +136,28 @@ func Socket(f, p, t int64, la, ra *syscall.Sockaddr) (fd *FD, err *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow reuse of recently-used addresses.
|
// Allow reuse of recently-used addresses.
|
||||||
syscall.setsockopt_int(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
syscall.setsockopt_int(s, syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1);
|
||||||
|
|
||||||
var r int64
|
var r int64;
|
||||||
if la != nil {
|
if la != nil {
|
||||||
r, e = syscall.bind(s, la)
|
r, e = syscall.bind(s, la);
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
syscall.close(s)
|
syscall.close(s);
|
||||||
return nil, os.ErrnoToError(e)
|
return nil, os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ra != nil {
|
if ra != nil {
|
||||||
r, e = syscall.connect(s, ra)
|
r, e = syscall.connect(s, ra);
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
syscall.close(s)
|
syscall.close(s);
|
||||||
return nil, os.ErrnoToError(e)
|
return nil, os.ErrnoToError(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fd, err = NewFD(s)
|
fd, err = NewFD(s);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
syscall.close(s)
|
syscall.close(s);
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,12 +179,12 @@ func (c *ConnBase) FD() int64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnBase) Read(b *[]byte) (n int, err *os.Error) {
|
func (c *ConnBase) Read(b *[]byte) (n int, err *os.Error) {
|
||||||
n, err = c.fd.Read(b)
|
n, err = c.fd.Read(b);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnBase) Write(b *[]byte) (n int, err *os.Error) {
|
func (c *ConnBase) Write(b *[]byte) (n int, err *os.Error) {
|
||||||
n, err = c.fd.Write(b)
|
n, err = c.fd.Write(b);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ func (c *ConnBase) ReadFrom(b *[]byte) (n int, raddr string, err *os.Error) {
|
||||||
if c == nil {
|
if c == nil {
|
||||||
return -1, "", os.EINVAL
|
return -1, "", os.EINVAL
|
||||||
}
|
}
|
||||||
n, err = c.Read(b)
|
n, err = c.Read(b);
|
||||||
return n, c.raddr, err
|
return n, c.raddr, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,7 +203,7 @@ func (c *ConnBase) WriteTo(raddr string, b *[]byte) (n int, err *os.Error) {
|
||||||
if raddr != c.raddr {
|
if raddr != c.raddr {
|
||||||
return -1, os.EINVAL
|
return -1, os.EINVAL
|
||||||
}
|
}
|
||||||
n, err = c.Write(b)
|
n, err = c.Write(b);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ func (c *ConnBase) SetKeepAlive(keepalive bool) *os.Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ConnBase) SetLinger(sec int) *os.Error {
|
func (c *ConnBase) SetLinger(sec int) *os.Error {
|
||||||
e := syscall.setsockopt_linger(c.FD(), syscall.SOL_SOCKET, syscall.SO_LINGER, sec)
|
e := syscall.setsockopt_linger(c.FD(), syscall.SOL_SOCKET, syscall.SO_LINGER, sec);
|
||||||
return os.ErrnoToError(e);
|
return os.ErrnoToError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,24 +281,24 @@ const PreferIPv4 = false
|
||||||
|
|
||||||
func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Error) {
|
func InternetSocket(net, laddr, raddr string, proto int64) (fd *FD, err *os.Error) {
|
||||||
// Parse addresses (unless they are empty).
|
// Parse addresses (unless they are empty).
|
||||||
var lip, rip *[]byte
|
var lip, rip *[]byte;
|
||||||
var lport, rport int
|
var lport, rport int;
|
||||||
var lerr, rerr *os.Error
|
var lerr, rerr *os.Error;
|
||||||
// BUG 6g doesn't zero var lists
|
// BUG 6g doesn't zero var lists
|
||||||
lip = nil;
|
lip = nil;
|
||||||
rip = nil;
|
rip = nil;
|
||||||
lport = 0;
|
lport = 0;
|
||||||
rport = 0;
|
rport = 0;
|
||||||
lerr = nil;
|
lerr = nil;
|
||||||
rerr = nil
|
rerr = nil;
|
||||||
if laddr != "" {
|
if laddr != "" {
|
||||||
lip, lport, lerr = HostPortToIP(net, laddr)
|
lip, lport, lerr = HostPortToIP(net, laddr);
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
return nil, lerr
|
return nil, lerr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if raddr != "" {
|
if raddr != "" {
|
||||||
rip, rport, rerr = HostPortToIP(net, raddr)
|
rip, rport, rerr = HostPortToIP(net, raddr);
|
||||||
if rerr != nil {
|
if rerr != nil {
|
||||||
return nil, rerr
|
return nil, rerr
|
||||||
}
|
}
|
||||||
|
@ -309,9 +309,9 @@ rerr = nil
|
||||||
vers := 0;
|
vers := 0;
|
||||||
switch net[len(net)-1] {
|
switch net[len(net)-1] {
|
||||||
case '4':
|
case '4':
|
||||||
vers = 4
|
vers = 4;
|
||||||
case '6':
|
case '6':
|
||||||
vers = 6
|
vers = 6;
|
||||||
default:
|
default:
|
||||||
// Otherwise, guess.
|
// Otherwise, guess.
|
||||||
// If the addresses are IPv4 and we prefer IPv4, use 4; else 6.
|
// If the addresses are IPv4 and we prefer IPv4, use 4; else 6.
|
||||||
|
@ -324,8 +324,8 @@ rerr = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var cvt *(addr *[]byte, port int) (sa *syscall.Sockaddr, err *os.Error)
|
var cvt *(addr *[]byte, port int) (sa *syscall.Sockaddr, err *os.Error);
|
||||||
var family int64
|
var family int64;
|
||||||
if vers == 4 {
|
if vers == 4 {
|
||||||
cvt = &IPv4ToSockaddr;
|
cvt = &IPv4ToSockaddr;
|
||||||
family = syscall.AF_INET
|
family = syscall.AF_INET
|
||||||
|
@ -337,7 +337,7 @@ rerr = nil
|
||||||
var la, ra *syscall.Sockaddr;
|
var la, ra *syscall.Sockaddr;
|
||||||
// BUG
|
// BUG
|
||||||
la = nil;
|
la = nil;
|
||||||
ra = nil
|
ra = nil;
|
||||||
if lip != nil {
|
if lip != nil {
|
||||||
la, lerr = cvt(lip, lport);
|
la, lerr = cvt(lip, lport);
|
||||||
if lerr != nil {
|
if lerr != nil {
|
||||||
|
@ -372,19 +372,19 @@ func (c *ConnTCP) SetNoDelay(nodelay bool) *os.Error {
|
||||||
|
|
||||||
// Wrappers
|
// Wrappers
|
||||||
func (c *ConnTCP) Read(b *[]byte) (n int, err *os.Error) {
|
func (c *ConnTCP) Read(b *[]byte) (n int, err *os.Error) {
|
||||||
n, err = (&c.base).Read(b)
|
n, err = (&c.base).Read(b);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
func (c *ConnTCP) Write(b *[]byte) (n int, err *os.Error) {
|
func (c *ConnTCP) Write(b *[]byte) (n int, err *os.Error) {
|
||||||
n, err = (&c.base).Write(b)
|
n, err = (&c.base).Write(b);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
func (c *ConnTCP) ReadFrom(b *[]byte) (n int, raddr string, err *os.Error) {
|
func (c *ConnTCP) ReadFrom(b *[]byte) (n int, raddr string, err *os.Error) {
|
||||||
n, raddr, err = (&c.base).ReadFrom(b)
|
n, raddr, err = (&c.base).ReadFrom(b);
|
||||||
return n, raddr, err
|
return n, raddr, err
|
||||||
}
|
}
|
||||||
func (c *ConnTCP) WriteTo(raddr string, b *[]byte) (n int, err *os.Error) {
|
func (c *ConnTCP) WriteTo(raddr string, b *[]byte) (n int, err *os.Error) {
|
||||||
n, err = (&c.base).WriteTo(raddr, b)
|
n, err = (&c.base).WriteTo(raddr, b);
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
func (c *ConnTCP) Close() *os.Error {
|
func (c *ConnTCP) Close() *os.Error {
|
||||||
|
@ -433,7 +433,7 @@ export func DialTCP(net, laddr, raddr string) (c *ConnTCP, err *os.Error) {
|
||||||
if raddr == "" {
|
if raddr == "" {
|
||||||
return nil, MissingAddress
|
return nil, MissingAddress
|
||||||
}
|
}
|
||||||
fd, e := InternetSocket(net, laddr, raddr, syscall.SOCK_STREAM)
|
fd, e := InternetSocket(net, laddr, raddr, syscall.SOCK_STREAM);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
|
@ -499,23 +499,23 @@ var noconn NoConn
|
||||||
export func Dial(net, laddr, raddr string) (c Conn, err *os.Error) {
|
export func Dial(net, laddr, raddr string) (c Conn, err *os.Error) {
|
||||||
switch net {
|
switch net {
|
||||||
case "tcp", "tcp4", "tcp6":
|
case "tcp", "tcp4", "tcp6":
|
||||||
c, err := DialTCP(net, laddr, raddr)
|
c, err := DialTCP(net, laddr, raddr);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &noconn, err
|
return &noconn, err
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil;
|
||||||
/*
|
/*
|
||||||
case "udp", "udp4", "upd6":
|
case "udp", "udp4", "upd6":
|
||||||
c, err := DialUDP(net, laddr, raddr)
|
c, err := DialUDP(net, laddr, raddr);
|
||||||
return c, err
|
return c, err;
|
||||||
case "ether":
|
case "ether":
|
||||||
c, err := DialEther(net, laddr, raddr)
|
c, err := DialEther(net, laddr, raddr);
|
||||||
return c, err
|
return c, err;
|
||||||
case "ipv4":
|
case "ipv4":
|
||||||
c, err := DialIPv4(net, laddr, raddr)
|
c, err := DialIPv4(net, laddr, raddr);
|
||||||
return c, err
|
return c, err;
|
||||||
case "ipv6":
|
case "ipv6":
|
||||||
c, err := DialIPv6(net, laddr, raddr)
|
c, err := DialIPv6(net, laddr, raddr);
|
||||||
return c, err
|
return c, err
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
@ -542,17 +542,17 @@ export type ListenerTCP struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func ListenTCP(net, laddr string) (l *ListenerTCP, err *os.Error) {
|
export func ListenTCP(net, laddr string) (l *ListenerTCP, err *os.Error) {
|
||||||
fd, e := InternetSocket(net, laddr, "", syscall.SOCK_STREAM)
|
fd, e := InternetSocket(net, laddr, "", syscall.SOCK_STREAM);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
r, e1 := syscall.listen(fd.fd, ListenBacklog())
|
r, e1 := syscall.listen(fd.fd, ListenBacklog());
|
||||||
if e1 != 0 {
|
if e1 != 0 {
|
||||||
syscall.close(fd.fd)
|
syscall.close(fd.fd);
|
||||||
return nil, os.ErrnoToError(e1)
|
return nil, os.ErrnoToError(e1)
|
||||||
}
|
}
|
||||||
l = new(ListenerTCP);
|
l = new(ListenerTCP);
|
||||||
l.fd = fd
|
l.fd = fd;
|
||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -561,20 +561,20 @@ func (l *ListenerTCP) AcceptTCP() (c *ConnTCP, raddr string, err *os.Error) {
|
||||||
return nil, "", os.EINVAL
|
return nil, "", os.EINVAL
|
||||||
}
|
}
|
||||||
var sa syscall.Sockaddr;
|
var sa syscall.Sockaddr;
|
||||||
fd, e := l.fd.Accept(&sa)
|
fd, e := l.fd.Accept(&sa);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, "", e
|
return nil, "", e
|
||||||
}
|
}
|
||||||
raddr, err = SockaddrToHostPort(&sa)
|
raddr, err = SockaddrToHostPort(&sa);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fd.Close()
|
fd.Close();
|
||||||
return nil, "", err
|
return nil, "", err
|
||||||
}
|
}
|
||||||
return NewConnTCP(fd, raddr), raddr, nil
|
return NewConnTCP(fd, raddr), raddr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *ListenerTCP) Accept() (c Conn, raddr string, err *os.Error) {
|
func (l *ListenerTCP) Accept() (c Conn, raddr string, err *os.Error) {
|
||||||
c1, r1, e1 := l.AcceptTCP()
|
c1, r1, e1 := l.AcceptTCP();
|
||||||
if e1 != nil {
|
if e1 != nil {
|
||||||
return &noconn, "", e1
|
return &noconn, "", e1
|
||||||
}
|
}
|
||||||
|
@ -591,7 +591,7 @@ func (l *ListenerTCP) Close() *os.Error {
|
||||||
export func Listen(net, laddr string) (l Listener, err *os.Error) {
|
export func Listen(net, laddr string) (l Listener, err *os.Error) {
|
||||||
switch net {
|
switch net {
|
||||||
case "tcp", "tcp4", "tcp6":
|
case "tcp", "tcp4", "tcp6":
|
||||||
l, err := ListenTCP(net, laddr)
|
l, err := ListenTCP(net, laddr);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &nolistener, err
|
return &nolistener, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
||||||
p = ToIPv4(p)
|
p = ToIPv4(p);
|
||||||
if p == nil || port < 0 || port > 0xFFFF {
|
if p == nil || port < 0 || port > 0xFFFF {
|
||||||
return nil, os.EINVAL
|
return nil, os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.
|
||||||
}
|
}
|
||||||
|
|
||||||
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
||||||
p = ToIPv6(p)
|
p = ToIPv6(p);
|
||||||
if p == nil || port < 0 || port > 0xFFFF {
|
if p == nil || port < 0 || port > 0xFFFF {
|
||||||
return nil, os.EINVAL
|
return nil, os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -46,18 +46,18 @@ export func SockaddrToIP(sa1 *syscall.Sockaddr) (p *[]byte, port int, err *os.Er
|
||||||
switch sa1.family {
|
switch sa1.family {
|
||||||
case syscall.AF_INET:
|
case syscall.AF_INET:
|
||||||
sa := syscall.SockaddrToSockaddrInet4(sa1);
|
sa := syscall.SockaddrToSockaddrInet4(sa1);
|
||||||
a := ToIPv6(&sa.addr)
|
a := ToIPv6(&sa.addr);
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil, 0, os.EINVAL
|
return nil, 0, os.EINVAL
|
||||||
}
|
}
|
||||||
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
|
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||||
case syscall.AF_INET6:
|
case syscall.AF_INET6:
|
||||||
sa := syscall.SockaddrToSockaddrInet6(sa1);
|
sa := syscall.SockaddrToSockaddrInet6(sa1);
|
||||||
a := ToIPv6(&sa.addr)
|
a := ToIPv6(&sa.addr);
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil, 0, os.EINVAL
|
return nil, 0, os.EINVAL
|
||||||
}
|
}
|
||||||
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
|
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||||
default:
|
default:
|
||||||
return nil, 0, os.EINVAL
|
return nil, 0, os.EINVAL
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
||||||
p = ToIPv4(p)
|
p = ToIPv4(p);
|
||||||
if p == nil || port < 0 || port > 0xFFFF {
|
if p == nil || port < 0 || port > 0xFFFF {
|
||||||
return nil, os.EINVAL
|
return nil, os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export func IPv4ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.
|
||||||
var IPv6zero [16]byte;
|
var IPv6zero [16]byte;
|
||||||
|
|
||||||
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
export func IPv6ToSockaddr(p *[]byte, port int) (sa1 *syscall.Sockaddr, err *os.Error) {
|
||||||
p = ToIPv6(p)
|
p = ToIPv6(p);
|
||||||
if p == nil || port < 0 || port > 0xFFFF {
|
if p == nil || port < 0 || port > 0xFFFF {
|
||||||
return nil, os.EINVAL
|
return nil, os.EINVAL
|
||||||
}
|
}
|
||||||
|
@ -54,18 +54,18 @@ export func SockaddrToIP(sa1 *syscall.Sockaddr) (p *[]byte, port int, err *os.Er
|
||||||
switch sa1.family {
|
switch sa1.family {
|
||||||
case syscall.AF_INET:
|
case syscall.AF_INET:
|
||||||
sa := syscall.SockaddrToSockaddrInet4(sa1);
|
sa := syscall.SockaddrToSockaddrInet4(sa1);
|
||||||
a := ToIPv6(&sa.addr)
|
a := ToIPv6(&sa.addr);
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil, 0, os.EINVAL
|
return nil, 0, os.EINVAL
|
||||||
}
|
}
|
||||||
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
|
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||||
case syscall.AF_INET6:
|
case syscall.AF_INET6:
|
||||||
sa := syscall.SockaddrToSockaddrInet6(sa1);
|
sa := syscall.SockaddrToSockaddrInet6(sa1);
|
||||||
a := ToIPv6(&sa.addr)
|
a := ToIPv6(&sa.addr);
|
||||||
if a == nil {
|
if a == nil {
|
||||||
return nil, 0, os.EINVAL
|
return nil, 0, os.EINVAL
|
||||||
}
|
}
|
||||||
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil
|
return a, int(sa.port[0])<<8 + int(sa.port[1]), nil;
|
||||||
default:
|
default:
|
||||||
return nil, 0, os.EINVAL
|
return nil, 0, os.EINVAL
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ var jobmap = new(map[*()]*Job)
|
||||||
func Server() {
|
func Server() {
|
||||||
for {
|
for {
|
||||||
req := <-service;
|
req := <-service;
|
||||||
job, present := jobmap[req.f]
|
job, present := jobmap[req.f];
|
||||||
if !present {
|
if !present {
|
||||||
job = new(Job);
|
job = new(Job);
|
||||||
job.doit = new(chan bool, 1);
|
job.doit = new(chan bool, 1);
|
||||||
|
@ -48,8 +48,8 @@ export func Do(f *()) {
|
||||||
// If not there, ask map server to make one.
|
// If not there, ask map server to make one.
|
||||||
// TODO: Uncomment use of jobmap[f] once
|
// TODO: Uncomment use of jobmap[f] once
|
||||||
// maps are thread-safe.
|
// maps are thread-safe.
|
||||||
var job *Job
|
var job *Job;
|
||||||
var present bool
|
var present bool;
|
||||||
// job, present = jobmap[f]
|
// job, present = jobmap[f]
|
||||||
if !present {
|
if !present {
|
||||||
c := new(chan *Job);
|
c := new(chan *Job);
|
||||||
|
|
|
@ -16,7 +16,7 @@ var ErrorTab = new(map[int64] *Error);
|
||||||
|
|
||||||
export func NewError(s string) *Error {
|
export func NewError(s string) *Error {
|
||||||
e := new(Error);
|
e := new(Error);
|
||||||
e.s = s
|
e.s = s;
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ export func ErrnoToError(errno int64) *Error {
|
||||||
if errno == 0 {
|
if errno == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
err, ok := ErrorTab[errno]
|
err, ok := ErrorTab[errno];
|
||||||
if ok {
|
if ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ func (fd *FD) WriteString(s string) (ret int, err *Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func Pipe() (fd1 *FD, fd2 *FD, err *Error) {
|
export func Pipe() (fd1 *FD, fd2 *FD, err *Error) {
|
||||||
var p [2]int64
|
var p [2]int64;
|
||||||
r, e := syscall.pipe(&p);
|
r, e := syscall.pipe(&p);
|
||||||
if e != 0 {
|
if e != 0 {
|
||||||
return nil, nil, ErrnoToError(e)
|
return nil, nil, ErrnoToError(e)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
export func Time() (sec int64, nsec int64, err *Error) {
|
export func Time() (sec int64, nsec int64, err *Error) {
|
||||||
var errno int64;
|
var errno int64;
|
||||||
sec, nsec, errno = syscall.gettimeofday()
|
sec, nsec, errno = syscall.gettimeofday();
|
||||||
if errno != 0 {
|
if errno != 0 {
|
||||||
return 0, 0, ErrnoToError(errno)
|
return 0, 0, ErrnoToError(errno)
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ srand(seed int32)
|
||||||
for i := -20; i < LEN; i++ {
|
for i := -20; i < LEN; i++ {
|
||||||
x = seedrand(x);
|
x = seedrand(x);
|
||||||
if i >= 0 {
|
if i >= 0 {
|
||||||
var u int64
|
var u int64;
|
||||||
u = int64(x) << 20;
|
u = int64(x) << 20;
|
||||||
x = seedrand(x);
|
x = seedrand(x);
|
||||||
u ^= int64(x) << 10;
|
u ^= int64(x) << 10;
|
||||||
|
@ -121,7 +121,7 @@ nrand63(n int64) int64
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
max := int64((1<<63)-1 - (1<<63) % uint64(n));
|
max := int64((1<<63)-1 - (1<<63) % uint64(n));
|
||||||
v := rand63()
|
v := rand63();
|
||||||
for v > max {
|
for v > max {
|
||||||
v = rand63()
|
v = rand63()
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ export func unlink(name string) (ret int64, errno int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
|
export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
|
||||||
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg)
|
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg);
|
||||||
return r1, err
|
return r1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,7 @@ export func unlink(name string) (ret int64, errno int64) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
|
export func fcntl(fd, cmd, arg int64) (ret int64, errno int64) {
|
||||||
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg)
|
r1, r2, err := Syscall(SYS_FCNTL, fd, cmd, arg);
|
||||||
return r1, err
|
return r1, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ export func setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err i
|
||||||
|
|
||||||
export func setsockopt_int(fd, level, opt int64, value int) int64 {
|
export func setsockopt_int(fd, level, opt int64, value int) int64 {
|
||||||
n := int32(opt);
|
n := int32(opt);
|
||||||
r1, e := setsockopt(fd, level, opt, Int32Ptr(&n), 4)
|
r1, e := setsockopt(fd, level, opt, Int32Ptr(&n), 4);
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ export func setsockopt_tv(fd, level, opt, nsec int64) int64 {
|
||||||
nsec += 999;
|
nsec += 999;
|
||||||
tv.sec = int64(nsec/1000000000);
|
tv.sec = int64(nsec/1000000000);
|
||||||
tv.usec = uint32(nsec%1000000000);
|
tv.usec = uint32(nsec%1000000000);
|
||||||
r1, e := setsockopt(fd, level, opt, TimevalPtr(&tv), 4)
|
r1, e := setsockopt(fd, level, opt, TimevalPtr(&tv), 4);
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,7 @@ export func setsockopt_linger(fd, level, opt int64, sec int) int64 {
|
||||||
l.yes = 0;
|
l.yes = 0;
|
||||||
l.sec = 0
|
l.sec = 0
|
||||||
}
|
}
|
||||||
r1, err := setsockopt(fd, level, opt, LingerPtr(&l), 8)
|
r1, err := setsockopt(fd, level, opt, LingerPtr(&l), 8);
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ export func SockaddrInet6ToSockaddr(s *SockaddrInet6) *Sockaddr;
|
||||||
func Len(s *Sockaddr) int64 {
|
func Len(s *Sockaddr) int64 {
|
||||||
switch s.family {
|
switch s.family {
|
||||||
case AF_UNIX:
|
case AF_UNIX:
|
||||||
return SizeofSockaddrUnix
|
return SizeofSockaddrUnix;
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
return SizeofSockaddrInet4
|
return SizeofSockaddrInet4;
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
return SizeofSockaddrInet6
|
return SizeofSockaddrInet6
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ export func setsockopt(fd, level, opt, valueptr, length int64) (ret int64, err i
|
||||||
|
|
||||||
export func setsockopt_int(fd, level, opt int64, value int) int64 {
|
export func setsockopt_int(fd, level, opt int64, value int) int64 {
|
||||||
n := int32(opt);
|
n := int32(opt);
|
||||||
r1, e := setsockopt(fd, level, opt, Int32Ptr(&n), 4)
|
r1, e := setsockopt(fd, level, opt, Int32Ptr(&n), 4);
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ export func setsockopt_tv(fd, level, opt, nsec int64) int64 {
|
||||||
nsec += 999;
|
nsec += 999;
|
||||||
tv.sec = int64(nsec/1000000000);
|
tv.sec = int64(nsec/1000000000);
|
||||||
tv.usec = uint64(nsec%1000000000);
|
tv.usec = uint64(nsec%1000000000);
|
||||||
r1, e := setsockopt(fd, level, opt, TimevalPtr(&tv), 4)
|
r1, e := setsockopt(fd, level, opt, TimevalPtr(&tv), 4);
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ export func setsockopt_linger(fd, level, opt int64, sec int) int64 {
|
||||||
l.yes = 0;
|
l.yes = 0;
|
||||||
l.sec = 0
|
l.sec = 0
|
||||||
}
|
}
|
||||||
r1, err := setsockopt(fd, level, opt, LingerPtr(&l), 8)
|
r1, err := setsockopt(fd, level, opt, LingerPtr(&l), 8);
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,14 +12,14 @@ import (
|
||||||
// Seconds since January 1, 1970 00:00:00 GMT
|
// Seconds since January 1, 1970 00:00:00 GMT
|
||||||
export func Seconds() (sec int64, err *os.Error) {
|
export func Seconds() (sec int64, err *os.Error) {
|
||||||
var nsec int64;
|
var nsec int64;
|
||||||
sec, nsec, err = os.Time()
|
sec, nsec, err = os.Time();
|
||||||
return sec, err
|
return sec, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nanoseconds since January 1, 1970 00:00:00 GMT
|
// Nanoseconds since January 1, 1970 00:00:00 GMT
|
||||||
export func Nanoseconds() (nsec int64, err *os.Error) {
|
export func Nanoseconds() (nsec int64, err *os.Error) {
|
||||||
var sec int64;
|
var sec int64;
|
||||||
sec, nsec, err = os.Time()
|
sec, nsec, err = os.Time();
|
||||||
return sec*1e9 + nsec, err
|
return sec*1e9 + nsec, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ export func SecondsToUTC(sec int64) *Time {
|
||||||
day := sec/SecondsPerDay;
|
day := sec/SecondsPerDay;
|
||||||
sec -= day*SecondsPerDay;
|
sec -= day*SecondsPerDay;
|
||||||
if sec < 0 {
|
if sec < 0 {
|
||||||
day--
|
day--;
|
||||||
sec += SecondsPerDay
|
sec += SecondsPerDay
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ export func SecondsToUTC(sec int64) *Time {
|
||||||
t.second = int(sec%60);
|
t.second = int(sec%60);
|
||||||
|
|
||||||
// Day 0 = January 1, 1970 was a Thursday
|
// Day 0 = January 1, 1970 was a Thursday
|
||||||
t.weekday = int((day + Thursday) % 7)
|
t.weekday = int((day + Thursday) % 7);
|
||||||
if t.weekday < 0 {
|
if t.weekday < 0 {
|
||||||
t.weekday += 7
|
t.weekday += 7
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ export func SecondsToUTC(sec int64) *Time {
|
||||||
// (2001 begins 4-, 100-, and 400-year cycles ending in a leap year.)
|
// (2001 begins 4-, 100-, and 400-year cycles ending in a leap year.)
|
||||||
day -= Days1970To2001;
|
day -= Days1970To2001;
|
||||||
|
|
||||||
year := int64(2001)
|
year := int64(2001);
|
||||||
if day < 0 {
|
if day < 0 {
|
||||||
// Go back enough 400 year cycles to make day positive.
|
// Go back enough 400 year cycles to make day positive.
|
||||||
n := -day/DaysPer400Years + 1;
|
n := -day/DaysPer400Years + 1;
|
||||||
|
@ -143,7 +143,7 @@ export func SecondsToUTC(sec int64) *Time {
|
||||||
|
|
||||||
export func UTC() (t *Time, err *os.Error) {
|
export func UTC() (t *Time, err *os.Error) {
|
||||||
var sec int64;
|
var sec int64;
|
||||||
sec, err = Seconds()
|
sec, err = Seconds();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ export func UTC() (t *Time, err *os.Error) {
|
||||||
|
|
||||||
// TODO: Should this return an error?
|
// TODO: Should this return an error?
|
||||||
export func SecondsToLocalTime(sec int64) *Time {
|
export func SecondsToLocalTime(sec int64) *Time {
|
||||||
zone, offset, err := time.LookupTimezone(sec)
|
zone, offset, err := time.LookupTimezone(sec);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SecondsToUTC(sec)
|
return SecondsToUTC(sec)
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ export func SecondsToLocalTime(sec int64) *Time {
|
||||||
|
|
||||||
export func LocalTime() (t *Time, err *os.Error) {
|
export func LocalTime() (t *Time, err *os.Error) {
|
||||||
var sec int64;
|
var sec int64;
|
||||||
sec, err = Seconds()
|
sec, err = Seconds();
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -225,7 +225,7 @@ func (t *Time) Seconds() int64 {
|
||||||
sec += Days1970To2001 * SecondsPerDay;
|
sec += Days1970To2001 * SecondsPerDay;
|
||||||
|
|
||||||
// Account for local time zone.
|
// Account for local time zone.
|
||||||
sec -= int64(t.zoneoffset)
|
sec -= int64(t.zoneoffset);
|
||||||
return sec
|
return sec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ func Decimal(dst *[]byte, n int) {
|
||||||
|
|
||||||
func AddString(buf *[]byte, bp int, s string) int {
|
func AddString(buf *[]byte, bp int, s string) int {
|
||||||
n := len(s);
|
n := len(s);
|
||||||
Copy(buf[bp:bp+n], s)
|
Copy(buf[bp:bp+n], s);
|
||||||
return bp+n
|
return bp+n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,21 +290,21 @@ func AddString(buf *[]byte, bp int, s string) int {
|
||||||
// Not exported.
|
// Not exported.
|
||||||
func Format(t *Time, fmt string) string {
|
func Format(t *Time, fmt string) string {
|
||||||
buf := new([]byte, 128);
|
buf := new([]byte, 128);
|
||||||
bp := 0
|
bp := 0;
|
||||||
|
|
||||||
for i := 0; i < len(fmt); i++ {
|
for i := 0; i < len(fmt); i++ {
|
||||||
if fmt[i] == '%' {
|
if fmt[i] == '%' {
|
||||||
i++
|
i++;
|
||||||
switch fmt[i] {
|
switch fmt[i] {
|
||||||
case 'A': // %A full weekday name
|
case 'A': // %A full weekday name
|
||||||
bp = AddString(buf, bp, LongDayNames[t.weekday])
|
bp = AddString(buf, bp, LongDayNames[t.weekday]);
|
||||||
case 'a': // %a abbreviated weekday name
|
case 'a': // %a abbreviated weekday name
|
||||||
bp = AddString(buf, bp, ShortDayNames[t.weekday])
|
bp = AddString(buf, bp, ShortDayNames[t.weekday]);
|
||||||
case 'b': // %b abbreviated month name
|
case 'b': // %b abbreviated month name
|
||||||
bp = AddString(buf, bp, ShortMonthNames[t.month-1])
|
bp = AddString(buf, bp, ShortMonthNames[t.month-1]);
|
||||||
case 'd': // %d day of month (01-31)
|
case 'd': // %d day of month (01-31)
|
||||||
Decimal(buf[bp:bp+2], t.day);
|
Decimal(buf[bp:bp+2], t.day);
|
||||||
bp += 2
|
bp += 2;
|
||||||
case 'e': // %e day of month ( 1-31)
|
case 'e': // %e day of month ( 1-31)
|
||||||
if t.day >= 10 {
|
if t.day >= 10 {
|
||||||
Decimal(buf[bp:bp+2], t.day)
|
Decimal(buf[bp:bp+2], t.day)
|
||||||
|
@ -312,24 +312,24 @@ func Format(t *Time, fmt string) string {
|
||||||
buf[bp] = ' ';
|
buf[bp] = ' ';
|
||||||
buf[bp+1] = byte(t.day + '0')
|
buf[bp+1] = byte(t.day + '0')
|
||||||
}
|
}
|
||||||
bp += 2
|
bp += 2;
|
||||||
case 'H': // %H hour 00-23
|
case 'H': // %H hour 00-23
|
||||||
Decimal(buf[bp:bp+2], t.hour);
|
Decimal(buf[bp:bp+2], t.hour);
|
||||||
bp += 2
|
bp += 2;
|
||||||
case 'M': // %M minute 00-59
|
case 'M': // %M minute 00-59
|
||||||
Decimal(buf[bp:bp+2], t.minute);
|
Decimal(buf[bp:bp+2], t.minute);
|
||||||
bp += 2
|
bp += 2;
|
||||||
case 'S': // %S second 00-59
|
case 'S': // %S second 00-59
|
||||||
Decimal(buf[bp:bp+2], t.second);
|
Decimal(buf[bp:bp+2], t.second);
|
||||||
bp += 2
|
bp += 2;
|
||||||
case 'Y': // %Y year 2008
|
case 'Y': // %Y year 2008
|
||||||
Decimal(buf[bp:bp+4], int(t.year));
|
Decimal(buf[bp:bp+4], int(t.year));
|
||||||
bp += 4
|
bp += 4;
|
||||||
case 'y': // %y year 08
|
case 'y': // %y year 08
|
||||||
Decimal(buf[bp:bp+2], int(t.year%100));
|
Decimal(buf[bp:bp+2], int(t.year%100));
|
||||||
bp += 2
|
bp += 2;
|
||||||
case 'Z':
|
case 'Z':
|
||||||
bp = AddString(buf, bp, t.zone)
|
bp = AddString(buf, bp, t.zone);
|
||||||
default:
|
default:
|
||||||
buf[bp] = '%';
|
buf[bp] = '%';
|
||||||
buf[bp+1] = fmt[i];
|
buf[bp+1] = fmt[i];
|
||||||
|
@ -337,7 +337,7 @@ func Format(t *Time, fmt string) string {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
buf[bp] = fmt[i];
|
buf[bp] = fmt[i];
|
||||||
bp++
|
bp++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return string(buf[0:bp])
|
return string(buf[0:bp])
|
||||||
|
|
|
@ -31,16 +31,16 @@ type Data struct {
|
||||||
|
|
||||||
func (d *Data) Read(n int) *[]byte {
|
func (d *Data) Read(n int) *[]byte {
|
||||||
if d.p == nil || len(d.p) < n {
|
if d.p == nil || len(d.p) < n {
|
||||||
d.p = nil
|
d.p = nil;
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
p := d.p[0:n];
|
p := d.p[0:n];
|
||||||
d.p = d.p[n:len(d.p)]
|
d.p = d.p[n:len(d.p)];
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) Big4() (n uint32, ok bool) {
|
func (d *Data) Big4() (n uint32, ok bool) {
|
||||||
p := d.Read(4)
|
p := d.Read(4);
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func (d *Data) Big4() (n uint32, ok bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Data) Byte() (n byte, ok bool) {
|
func (d *Data) Byte() (n byte, ok bool) {
|
||||||
p := d.Read(1)
|
p := d.Read(1);
|
||||||
if p == nil {
|
if p == nil {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
@ -89,11 +89,11 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 1-byte version, then 15 bytes of padding
|
// 1-byte version, then 15 bytes of padding
|
||||||
var p *[]byte
|
var p *[]byte;
|
||||||
if p = data.Read(16); p == nil || p[0] != 0 && p[0] != '2' {
|
if p = data.Read(16); p == nil || p[0] != 0 && p[0] != '2' {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
vers := p[0]
|
vers := p[0];
|
||||||
|
|
||||||
// six big-endian 32-bit integers:
|
// six big-endian 32-bit integers:
|
||||||
// number of UTC/local indicators
|
// number of UTC/local indicators
|
||||||
|
@ -110,9 +110,9 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
|
||||||
NZone;
|
NZone;
|
||||||
NChar
|
NChar
|
||||||
)
|
)
|
||||||
var n [6]int
|
var n [6]int;
|
||||||
for i := 0; i < 6; i++ {
|
for i := 0; i < 6; i++ {
|
||||||
nn, ok := data.Big4()
|
nn, ok := data.Big4();
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
|
@ -156,19 +156,19 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
|
||||||
// Now we can build up a useful data structure.
|
// Now we can build up a useful data structure.
|
||||||
// First the zone information.
|
// First the zone information.
|
||||||
// utcoff[4] isdst[1] nameindex[1]
|
// utcoff[4] isdst[1] nameindex[1]
|
||||||
zone := new([]Zone, n[NZone])
|
zone := new([]Zone, n[NZone]);
|
||||||
for i := 0; i < len(zone); i++ {
|
for i := 0; i < len(zone); i++ {
|
||||||
var ok bool;
|
var ok bool;
|
||||||
var n uint32
|
var n uint32;
|
||||||
if n, ok = zonedata.Big4(); !ok {
|
if n, ok = zonedata.Big4(); !ok {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
zone[i].utcoff = int(n)
|
zone[i].utcoff = int(n);
|
||||||
var b byte
|
var b byte;
|
||||||
if b, ok = zonedata.Byte(); !ok {
|
if b, ok = zonedata.Byte(); !ok {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
zone[i].isdst = b != 0
|
zone[i].isdst = b != 0;
|
||||||
if b, ok = zonedata.Byte(); !ok || int(b) >= len(abbrev) {
|
if b, ok = zonedata.Byte(); !ok || int(b) >= len(abbrev) {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
|
@ -176,14 +176,14 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now the transition time info.
|
// Now the transition time info.
|
||||||
zt = new([]Zonetime, n[NTime])
|
zt = new([]Zonetime, n[NTime]);
|
||||||
for i := 0; i < len(zt); i++ {
|
for i := 0; i < len(zt); i++ {
|
||||||
var ok bool;
|
var ok bool;
|
||||||
var n uint32
|
var n uint32;
|
||||||
if n, ok = txtimes.Big4(); !ok {
|
if n, ok = txtimes.Big4(); !ok {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
zt[i].time = int32(n)
|
zt[i].time = int32(n);
|
||||||
if int(txzones[i]) >= len(zone) {
|
if int(txzones[i]) >= len(zone) {
|
||||||
return nil, BadZoneinfo
|
return nil, BadZoneinfo
|
||||||
}
|
}
|
||||||
|
@ -199,35 +199,35 @@ func ParseZoneinfo(bytes *[]byte) (zt *[]Zonetime, err *os.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadFile(name string, max int) (p *[]byte, err *os.Error) {
|
func ReadFile(name string, max int) (p *[]byte, err *os.Error) {
|
||||||
fd, e := os.Open(name, os.O_RDONLY, 0)
|
fd, e := os.Open(name, os.O_RDONLY, 0);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
p = new([]byte, max+1)[0:0];
|
p = new([]byte, max+1)[0:0];
|
||||||
n := 0
|
n := 0;
|
||||||
for len(p) < max {
|
for len(p) < max {
|
||||||
nn, e := fd.Read(p[n:cap(p)])
|
nn, e := fd.Read(p[n:cap(p)]);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fd.Close()
|
fd.Close();
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
if nn == 0 {
|
if nn == 0 {
|
||||||
fd.Close()
|
fd.Close();
|
||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
p = p[0:n+nn]
|
p = p[0:n+nn]
|
||||||
}
|
}
|
||||||
fd.Close()
|
fd.Close();
|
||||||
return nil, BadZoneinfo // too long
|
return nil, BadZoneinfo // too long
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func ReadZoneinfoFile(name string) (tx *[]Zonetime, err *os.Error) {
|
func ReadZoneinfoFile(name string) (tx *[]Zonetime, err *os.Error) {
|
||||||
data, e := ReadFile(name, MaxFileSize)
|
data, e := ReadFile(name, MaxFileSize);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
}
|
}
|
||||||
tx, err = ParseZoneinfo(data)
|
tx, err = ParseZoneinfo(data);
|
||||||
return tx, err
|
return tx, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ func SetupZone() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) {
|
export func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) {
|
||||||
once.Do(&SetupZone)
|
once.Do(&SetupZone);
|
||||||
if zoneerr != nil || zones == nil || len(zones) == 0 {
|
if zoneerr != nil || zones == nil || len(zones) == 0 {
|
||||||
return "GMT", 0, zoneerr
|
return "GMT", 0, zoneerr
|
||||||
}
|
}
|
||||||
|
@ -259,6 +259,6 @@ export func LookupTimezone(sec int64) (zone string, offset int, err *os.Error) {
|
||||||
tz = tz[m:len(tz)]
|
tz = tz[m:len(tz)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
z := tz[0].zone
|
z := tz[0].zone;
|
||||||
return z.name, z.utcoff, nil
|
return z.name, z.utcoff, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,17 +36,17 @@ type ByteReader struct {
|
||||||
|
|
||||||
func NewByteReader(p *[]byte) io.Read {
|
func NewByteReader(p *[]byte) io.Read {
|
||||||
b := new(ByteReader);
|
b := new(ByteReader);
|
||||||
b.p = p
|
b.p = p;
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *ByteReader) Read(p *[]byte) (int, *os.Error) {
|
func (b *ByteReader) Read(p *[]byte) (int, *os.Error) {
|
||||||
n := len(p)
|
n := len(p);
|
||||||
if n > len(b.p) {
|
if n > len(b.p) {
|
||||||
n = len(b.p)
|
n = len(b.p)
|
||||||
}
|
}
|
||||||
Copy(p[0:n], b.p[0:n]);
|
Copy(p[0:n], b.p[0:n]);
|
||||||
b.p = b.p[n:len(b.p)]
|
b.p = b.p[n:len(b.p)];
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,12 +58,12 @@ type HalfByteReader struct {
|
||||||
|
|
||||||
func NewHalfByteReader(p *[]byte) io.Read {
|
func NewHalfByteReader(p *[]byte) io.Read {
|
||||||
b := new(HalfByteReader);
|
b := new(HalfByteReader);
|
||||||
b.p = p
|
b.p = p;
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *HalfByteReader) Read(p *[]byte) (int, *os.Error) {
|
func (b *HalfByteReader) Read(p *[]byte) (int, *os.Error) {
|
||||||
n := len(p)/2
|
n := len(p)/2;
|
||||||
if n == 0 && len(p) > 0 {
|
if n == 0 && len(p) > 0 {
|
||||||
n = 1
|
n = 1
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func (b *HalfByteReader) Read(p *[]byte) (int, *os.Error) {
|
||||||
n = len(b.p)
|
n = len(b.p)
|
||||||
}
|
}
|
||||||
Copy(p[0:n], b.p[0:n]);
|
Copy(p[0:n], b.p[0:n]);
|
||||||
b.p = b.p[n:len(b.p)]
|
b.p = b.p[n:len(b.p)];
|
||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,12 +82,12 @@ type Rot13Reader struct {
|
||||||
|
|
||||||
func NewRot13Reader(r io.Read) *Rot13Reader {
|
func NewRot13Reader(r io.Read) *Rot13Reader {
|
||||||
r13 := new(Rot13Reader);
|
r13 := new(Rot13Reader);
|
||||||
r13.r = r
|
r13.r = r;
|
||||||
return r13
|
return r13
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r13 *Rot13Reader) Read(p *[]byte) (int, *os.Error) {
|
func (r13 *Rot13Reader) Read(p *[]byte) (int, *os.Error) {
|
||||||
n, e := r13.r.Read(p)
|
n, e := r13.r.Read(p);
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return n, e
|
return n, e
|
||||||
}
|
}
|
||||||
|
@ -119,9 +119,9 @@ var readmakers = []*(p *[]byte) io.Read {
|
||||||
// Call ReadLineString (which ends up calling everything else)
|
// Call ReadLineString (which ends up calling everything else)
|
||||||
// to accumulate the text of a file.
|
// to accumulate the text of a file.
|
||||||
func ReadLines(b *bufio.BufRead) string {
|
func ReadLines(b *bufio.BufRead) string {
|
||||||
s := ""
|
s := "";
|
||||||
for {
|
for {
|
||||||
s1, e := b.ReadLineString('\n', true)
|
s1, e := b.ReadLineString('\n', true);
|
||||||
if e == bufio.EndOfFile {
|
if e == bufio.EndOfFile {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -136,9 +136,9 @@ func ReadLines(b *bufio.BufRead) string {
|
||||||
// Call ReadByte to accumulate the text of a file
|
// Call ReadByte to accumulate the text of a file
|
||||||
func ReadBytes(buf *bufio.BufRead) string {
|
func ReadBytes(buf *bufio.BufRead) string {
|
||||||
var b [1000]byte;
|
var b [1000]byte;
|
||||||
nb := 0
|
nb := 0;
|
||||||
for {
|
for {
|
||||||
c, e := buf.ReadByte()
|
c, e := buf.ReadByte();
|
||||||
if e == bufio.EndOfFile {
|
if e == bufio.EndOfFile {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -146,7 +146,7 @@ func ReadBytes(buf *bufio.BufRead) string {
|
||||||
panic("GetBytes: "+e.String())
|
panic("GetBytes: "+e.String())
|
||||||
}
|
}
|
||||||
b[nb] = c;
|
b[nb] = c;
|
||||||
nb++
|
nb++;
|
||||||
}
|
}
|
||||||
// BUG return string(b[0:nb]) ?
|
// BUG return string(b[0:nb]) ?
|
||||||
return string(b)[0:nb]
|
return string(b)[0:nb]
|
||||||
|
@ -155,11 +155,11 @@ func ReadBytes(buf *bufio.BufRead) string {
|
||||||
// Call Read to accumulate the text of a file
|
// Call Read to accumulate the text of a file
|
||||||
func Reads(buf *bufio.BufRead, m int) string {
|
func Reads(buf *bufio.BufRead, m int) string {
|
||||||
var b [1000]byte;
|
var b [1000]byte;
|
||||||
nb := 0
|
nb := 0;
|
||||||
for {
|
for {
|
||||||
// BUG parens around (&b) should not be needed
|
// BUG parens around (&b) should not be needed
|
||||||
n, e := buf.Read((&b)[nb:nb+m]);
|
n, e := buf.Read((&b)[nb:nb+m]);
|
||||||
nb += n
|
nb += n;
|
||||||
if e == bufio.EndOfFile {
|
if e == bufio.EndOfFile {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -219,9 +219,9 @@ func TestBufRead() {
|
||||||
bufsizes[16] = 1024;
|
bufsizes[16] = 1024;
|
||||||
bufsizes[17] = 4096;
|
bufsizes[17] = 4096;
|
||||||
|
|
||||||
var texts [31]string
|
var texts [31]string;
|
||||||
str := "";
|
str := "";
|
||||||
all := ""
|
all := "";
|
||||||
for i := 0; i < len(texts)-1; i++ {
|
for i := 0; i < len(texts)-1; i++ {
|
||||||
texts[i] = str + "\n";
|
texts[i] = str + "\n";
|
||||||
all += texts[i];
|
all += texts[i];
|
||||||
|
@ -242,11 +242,11 @@ func TestBufRead() {
|
||||||
|
|
||||||
for h := 0; h < len(texts); h++ {
|
for h := 0; h < len(texts); h++ {
|
||||||
text := texts[h];
|
text := texts[h];
|
||||||
textbytes := StringToBytes(text)
|
textbytes := StringToBytes(text);
|
||||||
for i := 0; i < len(readmakers); i++ {
|
for i := 0; i < len(readmakers); i++ {
|
||||||
readmaker := readmakers[i]
|
readmaker := readmakers[i];
|
||||||
for j := 0; j < len(bufreaders); j++ {
|
for j := 0; j < len(bufreaders); j++ {
|
||||||
bufreader := bufreaders[j]
|
bufreader := bufreaders[j];
|
||||||
for k := 0; k < len(bufsizes); k++ {
|
for k := 0; k < len(bufsizes); k++ {
|
||||||
bufsize := bufsizes[k];
|
bufsize := bufsizes[k];
|
||||||
read := readmaker(textbytes);
|
read := readmaker(textbytes);
|
||||||
|
@ -288,7 +288,7 @@ func (w *ByteWriter) Write(p *[]byte) (int, *os.Error) {
|
||||||
w.p = newp
|
w.p = newp
|
||||||
}
|
}
|
||||||
Copy(w.p[w.n:w.n+len(p)], p);
|
Copy(w.p[w.n:w.n+len(p)], p);
|
||||||
w.n += len(p)
|
w.n += len(p);
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,14 +304,14 @@ type HalfByteWriter struct {
|
||||||
|
|
||||||
func NewHalfByteWriter() WriteBuffer {
|
func NewHalfByteWriter() WriteBuffer {
|
||||||
w := new(HalfByteWriter);
|
w := new(HalfByteWriter);
|
||||||
w.bw = NewByteWriter()
|
w.bw = NewByteWriter();
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *HalfByteWriter) Write(p *[]byte) (int, *os.Error) {
|
func (w *HalfByteWriter) Write(p *[]byte) (int, *os.Error) {
|
||||||
n := (len(p)+1) / 2;
|
n := (len(p)+1) / 2;
|
||||||
// BUG return w.bw.Write(p[0:n])
|
// BUG return w.bw.Write(p[0:n])
|
||||||
r, e := w.bw.Write(p[0:n])
|
r, e := w.bw.Write(p[0:n]);
|
||||||
return r, e
|
return r, e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ func (w *HalfByteWriter) GetBytes() *[]byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBufWrite() {
|
func TestBufWrite() {
|
||||||
var data [8192]byte
|
var data [8192]byte;
|
||||||
|
|
||||||
var writers [2]*()WriteBuffer;
|
var writers [2]*()WriteBuffer;
|
||||||
writers[0] = &NewByteWriter;
|
writers[0] = &NewByteWriter;
|
||||||
|
@ -344,14 +344,14 @@ func TestBufWrite() {
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic("NewBufWriteSize error: "+e.String())
|
panic("NewBufWriteSize error: "+e.String())
|
||||||
}
|
}
|
||||||
n, e1 := buf.Write((&data)[0:nwrite])
|
n, e1 := buf.Write((&data)[0:nwrite]);
|
||||||
if e1 != nil {
|
if e1 != nil {
|
||||||
panic("buf.Write error "+e1.String())
|
panic("buf.Write error "+e1.String())
|
||||||
}
|
}
|
||||||
if n != nwrite {
|
if n != nwrite {
|
||||||
panic("buf.Write wrong count")
|
panic("buf.Write wrong count")
|
||||||
}
|
}
|
||||||
e = buf.Flush()
|
e = buf.Flush();
|
||||||
if e != nil {
|
if e != nil {
|
||||||
panic("buf.Flush error "+e.String())
|
panic("buf.Flush error "+e.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func main() {
|
||||||
if string(b1) != "hello" {
|
if string(b1) != "hello" {
|
||||||
panic("bad convert 1")
|
panic("bad convert 1")
|
||||||
}
|
}
|
||||||
var b2 = new([]byte, 5)
|
var b2 = new([]byte, 5);
|
||||||
for i := 0; i < 5; i++ { b2[i] = b1[i] }
|
for i := 0; i < 5; i++ { b2[i] = b1[i] }
|
||||||
if string(b2) != "hello" {
|
if string(b2) != "hello" {
|
||||||
panic("bad convert 2")
|
panic("bad convert 2")
|
||||||
|
|
|
@ -17,7 +17,7 @@ export type Stucky struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Stucky) Me() Iffy {
|
func (s *Stucky) Me() Iffy {
|
||||||
ncall++
|
ncall++;
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ func getn(in *[]*dch, n int) *[]item {
|
||||||
dat[i] = nil;
|
dat[i] = nil;
|
||||||
}
|
}
|
||||||
for n=2*n; n>0; n-- {
|
for n=2*n; n>0; n-- {
|
||||||
seqno++
|
seqno++;
|
||||||
|
|
||||||
select{
|
select{
|
||||||
case req[0] <- seqno:
|
case req[0] <- seqno:
|
||||||
|
@ -337,7 +337,7 @@ func Add(U, V PS) PS{
|
||||||
copy(V,Z);
|
copy(V,Z);
|
||||||
case 2:
|
case 2:
|
||||||
Z.dat <- uv[0];
|
Z.dat <- uv[0];
|
||||||
copy(U,Z)
|
copy(U,Z);
|
||||||
case 3:
|
case 3:
|
||||||
Z.dat <- finis;
|
Z.dat <- finis;
|
||||||
}
|
}
|
||||||
|
@ -612,7 +612,7 @@ func Init() {
|
||||||
|
|
||||||
func check(U PS, c item, count int, str string) {
|
func check(U PS, c item, count int, str string) {
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
r := get(U)
|
r := get(U);
|
||||||
if !r.eq(c) {
|
if !r.eq(c) {
|
||||||
print("got: ");
|
print("got: ");
|
||||||
r.pr();
|
r.pr();
|
||||||
|
@ -665,7 +665,7 @@ func main() {
|
||||||
checka(in, a, "Integ"); // 0 1 1/2 1/3 1/4 1/5
|
checka(in, a, "Integ"); // 0 1 1/2 1/3 1/4 1/5
|
||||||
check(Cmul(neg(one), Twos), itor(-2), 10, "CMul"); // -1 -1 -1 -1 -1
|
check(Cmul(neg(one), Twos), itor(-2), 10, "CMul"); // -1 -1 -1 -1 -1
|
||||||
check(Sub(Ones, Twos), itor(-1), 0, "Sub Ones Twos"); // -1 -1 -1 -1 -1
|
check(Sub(Ones, Twos), itor(-1), 0, "Sub Ones Twos"); // -1 -1 -1 -1 -1
|
||||||
m := Mul(Ones, Ones)
|
m := Mul(Ones, Ones);
|
||||||
// BUG: want array initializer
|
// BUG: want array initializer
|
||||||
for i:=0; i < N; i++ {
|
for i:=0; i < N; i++ {
|
||||||
a[i] = itor(int64(i+1))
|
a[i] = itor(int64(i+1))
|
||||||
|
|
|
@ -20,7 +20,7 @@ func Generate(ch *chan<- int) {
|
||||||
// removing those divisible by 'prime'.
|
// removing those divisible by 'prime'.
|
||||||
func Filter(in *<-chan int, out *chan<- int, prime int) {
|
func Filter(in *<-chan int, out *chan<- int, prime int) {
|
||||||
for {
|
for {
|
||||||
i := <-in // Receive value of new variable 'i' from 'in'.
|
i := <-in; // Receive value of new variable 'i' from 'in'.
|
||||||
if i % prime != 0 {
|
if i % prime != 0 {
|
||||||
out <- i // Send 'i' to channel 'out'.
|
out <- i // Send 'i' to channel 'out'.
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func Sieve(primes *chan<- int) {
|
||||||
func main() {
|
func main() {
|
||||||
primes := new(chan int);
|
primes := new(chan int);
|
||||||
go Sieve(primes);
|
go Sieve(primes);
|
||||||
a := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}
|
a := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
|
||||||
for i := 0; i < len(a); i++ {
|
for i := 0; i < len(a); i++ {
|
||||||
if <-primes != a[i] { panic(a[i])}
|
if <-primes != a[i] { panic(a[i])}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@ func FetchGoogle(fd net.Conn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDial(network, addr string) {
|
func TestDial(network, addr string) {
|
||||||
fd, err := net.Dial(network, "", addr)
|
fd, err := net.Dial(network, "", addr);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("net.Dial ", network, " ", addr, ": ", err.String())
|
panic("net.Dial ", network, " ", addr, ": ", err.String())
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ func TestDial(network, addr string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDialTCP(network, addr string) {
|
func TestDialTCP(network, addr string) {
|
||||||
fd, err := net.DialTCP(network, "", addr)
|
fd, err := net.DialTCP(network, "", addr);
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("net.DialTCP ", network, " ", addr, ": ", err.String())
|
panic("net.DialTCP ", network, " ", addr, ": ", err.String())
|
||||||
}
|
}
|
||||||
|
@ -87,20 +87,20 @@ var addrs = []string {
|
||||||
|
|
||||||
func main()
|
func main()
|
||||||
{
|
{
|
||||||
flag.Parse()
|
flag.Parse();
|
||||||
// If no ipv6 tunnel, don't try the last address.
|
// If no ipv6 tunnel, don't try the last address.
|
||||||
if !ipv6 {
|
if !ipv6 {
|
||||||
addrs[len(addrs)-1] = ""
|
addrs[len(addrs)-1] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(addrs); i++ {
|
for i := 0; i < len(addrs); i++ {
|
||||||
addr := addrs[i]
|
addr := addrs[i];
|
||||||
if addr == "" {
|
if addr == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// print(addr, "\n");
|
// print(addr, "\n");
|
||||||
TestDial("tcp", addr);
|
TestDial("tcp", addr);
|
||||||
TestDialTCP("tcp", addr)
|
TestDialTCP("tcp", addr);
|
||||||
if addr[0] != '[' {
|
if addr[0] != '[' {
|
||||||
TestDial("tcp4", addr);
|
TestDial("tcp4", addr);
|
||||||
TestDialTCP("tcp4", addr)
|
TestDialTCP("tcp4", addr)
|
||||||
|
|
|
@ -7,15 +7,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var i int
|
var i int;
|
||||||
var j int
|
var j int;
|
||||||
if true {}
|
if true {}
|
||||||
{ return }
|
{ return }
|
||||||
i = 0
|
i = 0;
|
||||||
if true {} else i++
|
if true {} else i++;
|
||||||
type s struct {};
|
type s struct {};
|
||||||
i = 0
|
i = 0;
|
||||||
type s2 int
|
type s2 int;
|
||||||
var k = func (a int) int { return a+1 }(3);
|
var k = func (a int) int { return a+1 }(3);
|
||||||
ro:
|
ro:
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ package main
|
||||||
var c *chan int
|
var c *chan int
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
c = new(chan int)
|
c = new(chan int);
|
||||||
go func() { print("ok\n"); c <- 0 } ();
|
go func() { print("ok\n"); c <- 0 } ();
|
||||||
<-c
|
<-c
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ send() bool
|
||||||
tots++;
|
tots++;
|
||||||
c.sv = expect(c.sv, c.sv);
|
c.sv = expect(c.sv, c.sv);
|
||||||
if c.sv == End {
|
if c.sv == End {
|
||||||
c.sc = nil
|
c.sc = nil;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -134,7 +134,7 @@ func Get() int
|
||||||
peekc = -1;
|
peekc = -1;
|
||||||
} else {
|
} else {
|
||||||
c = convert(int, input[inputindex]);
|
c = convert(int, input[inputindex]);
|
||||||
inputindex++
|
inputindex++;
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
lineno = lineno + 1;
|
lineno = lineno + 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ func main() {
|
||||||
var p P;
|
var p P;
|
||||||
var pp *P1;
|
var pp *P1;
|
||||||
var t T;
|
var t T;
|
||||||
var pt *T1
|
var pt *T1;
|
||||||
|
|
||||||
if s.val() != 1 { panicln("s.val:", s.val()) }
|
if s.val() != 1 { panicln("s.val:", s.val()) }
|
||||||
if ps.val() != 2 { panicln("ps.val:", ps.val()) }
|
if ps.val() != 2 { panicln("ps.val:", ps.val()) }
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var s string
|
var s string;
|
||||||
var ok bool
|
var ok bool;
|
||||||
|
|
||||||
s, ok = sys.readfile("readfile.go");
|
s, ok = sys.readfile("readfile.go");
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -17,7 +17,7 @@ func Generate(ch *chan<- int) {
|
||||||
// removing those divisible by 'prime'.
|
// removing those divisible by 'prime'.
|
||||||
func Filter(in *<-chan int, out *chan<- int, prime int) {
|
func Filter(in *<-chan int, out *chan<- int, prime int) {
|
||||||
for {
|
for {
|
||||||
i := <-in // Receive value of new variable 'i' from 'in'.
|
i := <-in; // Receive value of new variable 'i' from 'in'.
|
||||||
if i % prime != 0 {
|
if i % prime != 0 {
|
||||||
out <- i // Send 'i' to channel 'out'.
|
out <- i // Send 'i' to channel 'out'.
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func Serve(network, addr string, listening, done *chan<- int) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
echodone := new(chan int)
|
echodone := new(chan int);
|
||||||
go Echo(fd, echodone);
|
go Echo(fd, echodone);
|
||||||
<-echodone; // make sure Echo stops
|
<-echodone; // make sure Echo stops
|
||||||
l.Close();
|
l.Close();
|
||||||
|
|
|
@ -57,7 +57,7 @@ func main() {
|
||||||
sec := UTCTests[i].seconds;
|
sec := UTCTests[i].seconds;
|
||||||
golden := &UTCTests[i].golden;
|
golden := &UTCTests[i].golden;
|
||||||
t := time.SecondsToUTC(sec);
|
t := time.SecondsToUTC(sec);
|
||||||
newsec := t.Seconds()
|
newsec := t.Seconds();
|
||||||
if newsec != sec {
|
if newsec != sec {
|
||||||
panic("SecondsToUTC and back ", sec, " ", newsec)
|
panic("SecondsToUTC and back ", sec, " ", newsec)
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,7 @@ func main() {
|
||||||
sec := LocalTests[i].seconds;
|
sec := LocalTests[i].seconds;
|
||||||
golden := &LocalTests[i].golden;
|
golden := &LocalTests[i].golden;
|
||||||
t := time.SecondsToLocalTime(sec);
|
t := time.SecondsToLocalTime(sec);
|
||||||
newsec := t.Seconds()
|
newsec := t.Seconds();
|
||||||
if newsec != sec {
|
if newsec != sec {
|
||||||
panic("SecondsToLocalTime and back ", sec, " ", newsec)
|
panic("SecondsToLocalTime and back ", sec, " ", newsec)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func ReadImport(comp* Globals.Compilation, filename string, update bool) (data s
|
||||||
|
|
||||||
|
|
||||||
export func Import(comp *Globals.Compilation, pkg_file string) *Globals.Package {
|
export func Import(comp *Globals.Compilation, pkg_file string) *Globals.Package {
|
||||||
data, ok := ReadImport(comp, pkg_file, comp.flags.update_packages)
|
data, ok := ReadImport(comp, pkg_file, comp.flags.update_packages);
|
||||||
var pkg *Globals.Package;
|
var pkg *Globals.Package;
|
||||||
if ok {
|
if ok {
|
||||||
pkg = Importer.Import(comp, data);
|
pkg = Importer.Import(comp, data);
|
||||||
|
|
Загрузка…
Ссылка в новой задаче