We introduce a family of cotangent sums, functions defined over the rationals, that generalize the Dedekind sum and share with it the property of satisfying a reciprocity formula. These functions are related to the Nymann-Beurling criterion for the Riemann hypothesis and give (nearly) an example of what Zagier calls a ''quantum modular form''.

The reciprocity formula is obtained through the study of the period function (in the sense of Lewis and Zagier) of the Eisenstein series. We will show some properties of this period function and give as an application an exact formula for the (smoothed) second moment of the Riemann zeta-function.

Finally, we will give a continuity result for the error term in an approximate reciprocity relation (discovered by Conrey) for the twisted second moment of Dirichlet L-functions.