Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Supporg go 1

  • Loading branch information...
commit 6ef4bce7228d3f039230dc6224cf449552d33188 1 parent 4e55b14
@methane authored
Showing with 8 additions and 29 deletions.
  1. +1 −2  Makefile
  2. +7 −27 server_go.go
View
3  Makefile
@@ -19,8 +19,7 @@ null_server_thread: null_server_thread.cpp
$(CXX) $(CXXFLAGS) -o $@ $<
server_go: server_go.go
- 6g -o server_go.6 $<
- 6l -o $@ server_go.6
+ go build $<
server_haskell: server_haskell.hs
ghc6 -threaded -O --make -o $@ $<
View
34 server_go.go
@@ -1,47 +1,27 @@
-// Original: http://d.hatena.ne.jp/tokuhirom/20091112/1257995906
-
package main
import (
+ "log";
"net";
- "os";
- "fmt";
+ "io";
)
-func Err(format string, v ...os.Error) {
- fmt.Fprintf(os.Stderr, format + "\n", v)
-}
-
-func Handler(conn net.Conn) {
+func echo_handler(conn net.Conn) {
defer conn.Close();
-
- buffer := make([]byte, 24);
- for {
- l, e := conn.Read(buffer);
- switch {
- case e == nil:
- conn.Write(buffer[0:l])
- case e == os.EOF:
- return;
- case e != os.EAGAIN:
- Err("Err on receiving a header (%s)", e);
- return;
- }
- }
+ io.Copy(conn, conn);
}
func main() {
psock, e := net.Listen("tcp", ":5000");
if e != nil {
- Err("an error occured(%s)", e);
+ log.Fatal(e);
return
}
-
for {
conn, e := psock.Accept();
if e != nil {
- Err("an error occured(%s)", e);
+ log.Fatal(e);
return
}
- go Handler(conn);
+ go echo_handler(conn);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.