Skip to content
This repository has been archived by the owner on Mar 22, 2021. It is now read-only.

Commit

Permalink
Update the communication chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
miekg committed Mar 6, 2011
1 parent 01c67d6 commit bff2b1d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
1 change: 1 addition & 0 deletions Changelog
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
xx fff 2011: 0.4 Miek Gieben <miek@miek.nl> xx fff 2011: 0.4 Miek Gieben <miek@miek.nl>
* Fixes * Fixes
* Use hyperref, accurate numbering in the pdf and clickable links
* Functions: callbacks, closures added * Functions: callbacks, closures added
* Functions: panic, recover added (TODO) * Functions: panic, recover added (TODO)
* Communication: Dial, netchan added (TODO) * Communication: Dial, netchan added (TODO)
Expand Down
4 changes: 2 additions & 2 deletions about-miekg.tex
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
Miek Gieben has a masters in Computer Science from the Radboud University in Nijmegen. Miek Gieben has a master's degree in Computer Science from the Radboud University Nijmegen (Netherlands).
\begin{wrapfigure}{r}{0.3\textwidth} \begin{wrapfigure}{r}{0.3\textwidth}
\begin{center} \begin{center}
\includegraphics[width=3cm]{fig/avatar-miekg-300x300} \includegraphics[width=3cm]{fig/avatar-miekg-300x300}
Expand All @@ -11,7 +11,7 @@
that actually stuck with him. that actually stuck with him.


He fills his spare time with coding in, and writing of Go. He is the maintainer He fills his spare time with coding in, and writing of Go. He is the maintainer
of a Go DNS library: \url{https://github.com/miekg/godns}. of the Go DNS library: \url{https://github.com/miekg/godns}.


He maintains a personal blog on \url{http://www.miek.nl} and tweets He maintains a personal blog on \url{http://www.miek.nl} and tweets
under the name \texttt{@miekg}. The postings and tweets may sometimes under the name \texttt{@miekg}. The postings and tweets may sometimes
Expand Down
20 changes: 19 additions & 1 deletion go-communication.tex
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,10 +89,28 @@ \section{Executing commands}
\func{exit code}, with: \func{exit code}, with:
\begin{lstlisting} \begin{lstlisting}
w := os.Wait(pid, os.WNOHANG) w := os.Wait(pid, os.WNOHANG)
e := w.WaitStatus.ExitStatus() |\coderemark{ExitStatus() return an integer}| e := w.WaitStatus.ExitStatus() |\coderemark{ExitStatus() returns an integer}|
\end{lstlisting} \end{lstlisting}


\section{Networking} \section{Networking}
All network related types and functions can be found in the package \package{net}. One of the
most important functions in there is \func{Dial}\index{networking!Dial}. When you \func{Dial}
into a remote system the function returns a \var{Conn} interface type, which can be used
to send and receive information. The function \func{Dial} neatly abstracts away the network
family and transport. So IPv4 or IPv6, TCP or UDP can all share a common interface.

Dialing a remote system (port 80) over TCP, then UDP and lastly TCP over IPv6 looks
like this:\footnote{In case
you are wondering, 192.0.32.10 and 2620:0:2d0:200::10 are \url{www.example.org}.}
\begin{lstlisting}
conn, err := Dial("tcp", "", "192.0.32.10:80")
conn, err := Dial("udp", "", "192.0.32.10:80")
conn, err := Dial("tcp", "", "[2620:0:2d0:200::10]:80") |\coderemark{Brackets are mandatory}|
\end{lstlisting}

And with \var{conn} you can do read/write \todo{dkls}.

\todo{Write echo server}


\section{Netchan: networking and channels} \section{Netchan: networking and channels}
%%http://blog.golang.org/2010/09/go-concurrency-patterns-timing-out-and.html %%http://blog.golang.org/2010/09/go-concurrency-patterns-timing-out-and.html
Expand Down
2 changes: 1 addition & 1 deletion go-interfaces.tex
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ \section{A sorting example}
\item Write a \emph{generic} Sort function that works on the \type{Sorter} interface. \item Write a \emph{generic} Sort function that works on the \type{Sorter} interface.
\begin{lstlisting} \begin{lstlisting}
func Sort(x Sorter) { |\longremark{\var{x} is now of the \texttt{Sorter} type;}| func Sort(x Sorter) { |\longremark{\var{x} is now of the \texttt{Sorter} type;}|
for i := 0; i < x.Len()-1; i++ { |\longremark{Using the defined functions, we implement Bubblesort;}| for i := 0; i < x.Len() - 1; i++ { |\longremark{Using the defined functions, we implement Bubblesort.}|
for j := i + 1; j < x.Len(); j++ { for j := i + 1; j < x.Len(); j++ {
if x.Less(i, j) { if x.Less(i, j) {
x.Swap(i, j) x.Swap(i, j)
Expand Down

0 comments on commit bff2b1d

Please sign in to comment.